void control_set_mol_params(ATOMMAPS *atommaps,CPOPTS *cpopts,
                         CPCOEFFS_INFO *cpcoeffs_info,CP_PARSE *cp_parse,
                         CLASS_PARSE *class_parse,
                         BONDED *bonded,SURFACE *surface,
                         FILENAME_PARSE *filename_parse,
                         FREE_PARSE *free_parse,
                         DICT_MOL *dict_mol,DICT_WORD *word,
                         char *fun_key,int *nfun_key,
                         int iextend,double t_ext,int ifirst,int pi_beads)
/*=======================================================================*/
{/*begin routine*/
/*=======================================================================*/
/*             Local variable declarations                               */

  int   nline,nkey,i,num,ierr;
  FILE *fp;
  int  *mol_ind_chk;                                 /* Index check      */
  int  *ifound;

  int nmol_typ            = atommaps->nmol_typ;
  int *nmol_jmol_typ      = atommaps->nmol_jmol_typ;
  int *nres_1mol_jmol_typ = atommaps->nres_1mol_jmol_typ;

  int num_fun_dict        = dict_mol->num_fun_dict;
  char *molsetname        = filename_parse->molsetname;

  int bond_free_num       = bonded->bond_free.num;
  int bend_free_num       = bonded->bend_free.num;
  int tors_free_num       = bonded->tors_free.num;
  int rbar_sig_free_iopt  = bonded->rbar_sig_free.iopt;

  int *imoltyp_rbar1_free;
  int *imoltyp_rbar2_free;
  int *imol_rbar1_free;
  int *imol_rbar2_free;
  int *ires_rbar1_free;
  int *ires_rbar2_free;
  int nbar_bond;

  int *imoltyp_bond_free = free_parse->imoltyp_bond_free;
  int *imol_bond_free     = free_parse->imol_bond_free;
  int *ires_bond_free    = free_parse->ires_bond_free;
  int *iatm_bond_free    = free_parse->iatm_bond_free;

  int *imoltyp_bend_free = free_parse->imoltyp_bend_free;
  int *imol_bend_free     = free_parse->imol_bend_free;
  int *ires_bend_free    = free_parse->ires_bend_free;
  int *iatm_bend_free    = free_parse->iatm_bend_free;

  int *imoltyp_tors_free = free_parse->imoltyp_tors_free;
  int *imol_tors_free     = free_parse->imol_tors_free;
  int *ires_tors_free    = free_parse->ires_tors_free; 
  int *iatm_tors_free    = free_parse->iatm_tors_free;

/*=======================================================================*/
/* 0) Set up molecular index checking memory                             */

  mol_ind_chk     = (int *) cmalloc(nmol_typ*sizeof(int))-1;
  ifound          = (int *) cmalloc(num_fun_dict*sizeof(int))-1;
  for(i=1;i<=nmol_typ;i++){ mol_ind_chk[i]=0;}
  for(i=1;i<=num_fun_dict;i++){ ifound[i]=0;}

/*=======================================================================*/
/* I) Fetch a valid functional key word from molset file                 */

  fp = cfopen(molsetname,"r");

  nline          = 1;
  *nfun_key      = 0;
  word->iuset    = 0;
  word->key_type = 0;
  while(get_fun_key(fp,fun_key,&nline,nfun_key,molsetname)){
    get_fun_key_index(fun_key,dict_mol->num_fun_dict,dict_mol->fun_dict,
                      nline,*nfun_key,molsetname,&num);

/*=======================================================================*/
/* II) Fetch the key words and key args of the functional key word       */
/*     and stick them into the correct dictionary                        */

    if(num==1){
      set_mol_dict(&(dict_mol->mol_dict),&(dict_mol->num_mol_dict),
                 iextend,class_parse->tau_nhc_def,t_ext,ifirst);
    }
    nkey=0;
    while(get_word(fp,word,&nline,&nkey,*nfun_key,molsetname)){
      switch(num){
      case 1:
       put_word_dict(word,dict_mol->mol_dict,dict_mol->num_mol_dict,
                    fun_key,nline,nkey,*nfun_key,molsetname);
       break;
      case 2:
       put_word_dict(word,dict_mol->wave_dict,
                    dict_mol->num_wave_dict,fun_key,nline,nkey,
                    *nfun_key,molsetname);
       break;
      case 3:
       put_word_dict(word,dict_mol->bond_free_dict,
                    dict_mol->num_bond_free_dict,fun_key,nline,
                    nkey,*nfun_key,molsetname);
       break;
      case 4:
       put_word_dict(word,dict_mol->bend_free_dict,
                    dict_mol->num_bend_free_dict,fun_key,nline,
                    nkey,*nfun_key,molsetname);
       break;
      case 5:
       put_word_dict(word,dict_mol->tors_free_dict,
                    dict_mol->num_tors_free_dict,fun_key,nline,
                    nkey,*nfun_key,molsetname);
       break;
      case 6:
       put_word_dict(word,dict_mol->def_base_dict,
                    dict_mol->num_def_base_dict,fun_key,nline,
                    nkey,*nfun_key,molsetname);
       break;
      case 7:
       put_word_dict(word,dict_mol->user_base_dict,
                    dict_mol->num_user_base_dict,fun_key,nline,
                    nkey,*nfun_key,molsetname);
       break;
      case 8:
       put_word_dict(word,dict_mol->rbar_free_dict,
                    dict_mol->num_rbar_free_dict,fun_key,nline,
                    nkey,*nfun_key,molsetname);
       break;
      case 9:
       put_word_dict(word,dict_mol->surface_dict,
                    dict_mol->num_surface_dict,fun_key,nline,
                    nkey,*nfun_key,molsetname);
       break;
      } /* end switch dictionary fills*/
    } /* endwhile fetching keywords and keyargs*/
  
/*=====================================================================*/
/* III) Assign the key args of the key words to the appropriate        */
/*      program variables                                              */

    ifound[num]=1;
    switch(num){
    case 1:
      set_mol_params(filename_parse,fun_key,dict_mol->mol_dict,
                   dict_mol->num_mol_dict,
                   class_parse,atommaps,mol_ind_chk,pi_beads);
      break;

    case 2:
      set_wave_params(molsetname,fun_key,
                    dict_mol->wave_dict,dict_mol->num_wave_dict,
                    cpopts,cpcoeffs_info,cp_parse);
      break;
      
    case 3:
      set_bond_free_params(molsetname,fun_key,
                        dict_mol->bond_free_dict,
                        dict_mol->num_bond_free_dict,
                        &(bonded->bond_free),free_parse,
                        atommaps->nmol_typ);
      break;
    case 4:
      set_bend_free_params(molsetname,fun_key,
                        dict_mol->bend_free_dict,
                        dict_mol->num_bend_free_dict,
                        &(bonded->bend_free),free_parse,
                        atommaps->nmol_typ);
      break;
      
    case 5:
      set_tors_free_params(molsetname,fun_key,
                        dict_mol->tors_free_dict,
                        dict_mol->num_tors_free_dict,
                        &(bonded->tors_free),free_parse,
                        atommaps->nmol_typ);
      break;
    case 6:
      set_def_base_params(filename_parse,dict_mol->def_base_dict,
                       dict_mol->num_def_base_dict);
      break;
    case 7:
      set_user_base_params(filename_parse,dict_mol->user_base_dict,
                        dict_mol->num_user_base_dict);
      break;
    case 8:
      set_rbar_free_params(molsetname,fun_key,
                        dict_mol->rbar_free_dict,
                        dict_mol->num_rbar_free_dict,
                        &(bonded->rbar_sig_free),free_parse,
                        atommaps->nmol_typ);
      break;
    case 9:
      set_surf_params(molsetname,fun_key,
                      dict_mol->surface_dict,
                      dict_mol->num_surface_dict,
                      surface); 
      break;
    } /* end switch assigning dict stuff to variables */

  } /*endwhile getting functional keywords data*/

/*=====================================================================*/
/* IV) Make sure everything that is required has been found            */ 
/*     if it hasn't either die or define defaults                      */ 

  if(ifound[1]==0){
    printf("@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
    printf("  Required functional keyword %s not found     \n",
              dict_mol->fun_dict[1].keyword);
    printf("@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
    fflush(stdout);
    exit(1);
  }/*endif*/
  if(ifound[6]==0){
    set_def_base_params(filename_parse,dict_mol->def_base_dict,
                     dict_mol->num_def_base_dict);
  }/*endif*/
  if(ifound[7]==0){
    set_user_base_params(filename_parse,dict_mol->user_base_dict,
                      dict_mol->num_user_base_dict);
  }/*endif*/
  
/*=======================================================================*/
/* IV) Check  indices                                                    */

  for(i = 1;i<=nmol_typ;i++){
    if(mol_ind_chk[i]!=1){
      printf("@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@  \n");
      printf("Molecule number %d specified %d times in file %s \n",
              i,mol_ind_chk[i],molsetname);
      printf("@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@  \n");
      fflush(stdout);
      exit(1);
    }/*endif*/
  } /*endfor*/

/*=======================================================================*/
/* V) Check  free energy indices                                         */

  ierr = 0;

  if(bond_free_num>0){
    for(i=1;i<=2;i++){
      if(imol_bond_free[i]>nmol_jmol_typ[imoltyp_bond_free[i]]){ierr=i;}
      if(ires_bond_free[i]>MAX(nres_1mol_jmol_typ[imoltyp_bond_free[i]],1))
                                                               {ierr=i;}
    }/*endfor*/
  }/*endif*/

  if(bend_free_num>0){
    for(i=1;i<=3;i++){
      if(imol_bend_free[i]>nmol_jmol_typ[imoltyp_bend_free[i]]){ierr=i;}
      if(ires_bend_free[i]>MAX(nres_1mol_jmol_typ[imoltyp_bend_free[i]],1))
                                                               {ierr=i;}
    }/*endfor*/
  }/*endif*/

  if(tors_free_num>0){tors_free_num=bonded->tors_free.num;}
  if(tors_free_num==1){
    for(i=1;i<=4;i++){
      if(imol_tors_free[i]>nmol_jmol_typ[imoltyp_tors_free[i]]){ierr=i;}
      if(ires_tors_free[i]>MAX(nres_1mol_jmol_typ[imoltyp_tors_free[i]],1))
                                                               {ierr=i;}
    }/*endfor*/
  }/*endif*/
  if(tors_free_num==2){
    for(i=1;i<=8;i++){
      if(imol_tors_free[i]>nmol_jmol_typ[imoltyp_tors_free[i]]){ierr=i;}
      if(ires_tors_free[i]>MAX(nres_1mol_jmol_typ[imoltyp_tors_free[i]],1))
                                                               {ierr=i;}
    }/*endfor*/
  }/*endif*/

  if(rbar_sig_free_iopt>0){

    imoltyp_rbar1_free = free_parse->imoltyp_rbar1_free;
    imoltyp_rbar2_free = free_parse->imoltyp_rbar2_free;
    imol_rbar1_free    = free_parse->imol_rbar1_free;
    imol_rbar2_free    = free_parse->imol_rbar2_free;
    ires_rbar1_free    = free_parse->ires_rbar1_free;
    ires_rbar2_free    = free_parse->ires_rbar2_free;
    nbar_bond          = free_parse->nbar_bond;

    for(i=1;i<=nbar_bond;i++){
     if(imol_rbar1_free[i]>nmol_jmol_typ[imoltyp_rbar1_free[i]]){ierr=1;}
     if(imol_rbar2_free[i]>nmol_jmol_typ[imoltyp_rbar2_free[i]]){ierr=2;}
     if(ires_rbar1_free[i]>
              MAX(nres_1mol_jmol_typ[imoltyp_rbar1_free[i]],1)){ierr=1;}
     if(ires_rbar2_free[i]>
              MAX(nres_1mol_jmol_typ[imoltyp_rbar2_free[i]],1)){ierr=2;}
    }/*endfor*/
  }/*endif*/

  if(ierr>0){
      printf("@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
      printf("Error specifing the %dth atom in a free energy def \n",ierr);
      printf("in set up file %s \n",molsetname);
      printf("@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
      fflush(stdout);
      exit(1);
  }/*endif*/ 

/*=======================================================================*/
/* VI) Free memory                                                       */

  cfree(&mol_ind_chk[1]);
  cfree(&ifound[1]);

/*-----------------------------------------------------------------------*/
   }/*end routine*/
Exemple #2
0
void control_mol_params(MDINTEGRATE *mdintegrate, MDATOMS *mdatoms, 
    MDINTER *mdinter, GENERAL_DATA *general_data,
    MDINTRA *mdintra,CP *cp,
    CLASS_PARSE *class_parse,CP_PARSE *cp_parse,
    FREE_PARSE *free_parse,
    FILENAME_PARSE *filename_parse)

  /*==========================================================================*/
{ /*begin routine*/
  /*========================================================================*/
  /*             Local variable declarations                                */

#include "../class_defs/allclass_strip_mdatoms.h"
#include "../class_defs/allclass_strip_mdintegrate.h"
#include "../class_defs/allclass_strip_mdinter.h"
#include "../class_defs/allclass_strip_mdintra.h"
#include "../class_defs/allclass_strip_gen.h"
#include "../class_defs/allclass_strip_cp.h"

  int i,iii,jmol_typ,nmol_tot; 
  int nmol_typ,bond_free_num,bend_free_num,tors_free_num,rbar_sig_free_iopt;
  int ifirst,nline,nfun_key;
  int num_user,num_def,cp_on;
  double now_memory;
  char *fun_key;
  int nhist,nhist_bar,nhist_sig,nfree,nsurf;

  FILE *fp; 
  DICT_MOL dict_mol;                        /* Dictionaries and sizes */
  DICT_WORD *word;

  char *molsetname   = filename_parse->molsetname;
  double *text_mol;
  double *text_nhc_mol;
  int    *mol_freeze_opt;
  int    *imol_nhc_opt;
  int    *nmol_jmol_typ;
  int pi_beads       = mdatoms->mdclatoms_info.pi_beads;
  int iextend,ipress;
  iextend            = (general_data->genensopts.nvt 
      +general_data->genensopts.npt_i  
      +general_data->genensopts.npt_f
      +general_data->genensopts.nst);
  ipress             = (general_data->genensopts.npt_i
      +general_data->genensopts.npt_f);

  cp_on  =    general_data->gensimopts.cp_min 
    + general_data->gensimopts.cp_wave_min 
    + general_data->gensimopts.cp_wave_min_pimd
    + general_data->gensimopts.cp
    + general_data->gensimopts.cp_wave
    + general_data->gensimopts.cp_pimd 
    + general_data->gensimopts.cp_wave_pimd
    + general_data->gensimopts.debug_cp
    + general_data->gensimopts.debug_cp_pimd;


  /*========================================================================*/
  /* 0) Output to screen */

  PRINTF("\n");  PRINT_LINE_STAR;
  PRINTF("Reading molecular set up file %s\n",molsetname);
  PRINT_LINE_DASH;PRINTF("\n");

  /*========================================================================*/
  /* I) Set up dictionaries and malloc temporaries                          */

  ifirst = 1;

  set_molset_fun_dict(&dict_mol.fun_dict,&dict_mol.num_fun_dict);
  set_mol_dict(&dict_mol.mol_dict,&dict_mol.num_mol_dict,
      iextend,class_parse->tau_nhc_def,
      general_data->genstatepoint.t_ext,ifirst);

  set_wave_dict(&dict_mol.wave_dict,&dict_mol.num_wave_dict,cp_parse);
  set_bond_free_dict(&dict_mol.bond_free_dict,&dict_mol.num_bond_free_dict);
  set_bend_free_dict(&dict_mol.bend_free_dict,&dict_mol.num_bend_free_dict);
  set_tors_free_dict(&dict_mol.tors_free_dict,&dict_mol.num_tors_free_dict); 
  set_rbar_free_dict(&dict_mol.rbar_free_dict,&dict_mol.num_rbar_free_dict); 
  set_user_base_dict(&dict_mol.user_base_dict,&dict_mol.num_user_base_dict);   
  set_def_base_dict(&dict_mol.def_base_dict,&dict_mol.num_def_base_dict);
  set_surf_dict(&dict_mol.surface_dict,&dict_mol.num_surface_dict);
  num_user = dict_mol.num_user_base_dict;
  num_def  = dict_mol.num_def_base_dict;

  word = (DICT_WORD *)cmalloc(sizeof(DICT_WORD),"control_mol_params");
  fun_key = (char *)cmalloc(MAXWORD*sizeof(char),"control_mol_params");

  /*========================================================================*/
  /* II) Read the moleset file and count the molecule types                 */
  /*       and the free energy stuff                                        */

  nmol_typ            = 0;
  nline               = 0;
  nfun_key            = 0;
  bond_free_num       = 0;
  bend_free_num       = 0;
  tors_free_num       = 0;
  rbar_sig_free_iopt  = 0;
  nsurf               = 0;

  fp = cfopen((const char *) molsetname,"r");
  while(get_fun_key_cnt(fp,fun_key,&nline,&nfun_key,molsetname)){
    if(!strcasecmp(fun_key,"molecule_def")) {nmol_typ+=1;}
    if(!strcasecmp(fun_key,"bond_free_def")){bond_free_num+=1;}
    if(!strcasecmp(fun_key,"bend_free_def")){bend_free_num+=1;}
    if(!strcasecmp(fun_key,"tors_free_def")){tors_free_num+=1;}
    if(!strcasecmp(fun_key,"rbar_sig_free_def")){rbar_sig_free_iopt+=1;}
    if(!strcasecmp(fun_key,"surface_def")){nsurf+=1;}
  }/*endwhile*/
  fclose(fp);

  mdatom_maps->nmol_typ          = nmol_typ;
  mdintra->mdbond_free.num       = bond_free_num;
  mdintra->mdbend_free.num       = bend_free_num;
  mdintra->mdtors_free.num       = tors_free_num;
  mdintra->mdrbar_sig_free.iopt  = rbar_sig_free_iopt ;
  mdintra->mdrbar_sig_free.nfree = 0;

  if((bond_free_num+bend_free_num+tors_free_num+rbar_sig_free_iopt)>1){
    PRINTF("@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
    PRINTF("Only one free energy definition permitted\n");
    PRINTF("in set up file %s \n",molsetname);
    PRINTF("@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
    FFLUSH(stdout);
    EXIT(1);
  }/*endif*/

#ifdef JUNK
  int iperd          = general_data->gencell.iperd;
  if( (nsurf>0) && (iperd != 2)){
    PRINTF("@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
    PRINTF("Surface potentials permitted ONLY in systems with\n");
    PRINTF("2D periodicity in set up file  %s \n",molsetname);
    PRINTF("@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
    FFLUSH(stdout);
    EXIT(1);
  }/*endif*/
#endif

  mdsurface->isurf_on = nsurf;

  //========================================================================
  // III) Malloc molecular data storage and initialize                      

  now_memory = (double)((nmol_typ)*(sizeof(int)*2))*1.e-06;
  (*tot_memory) += now_memory;

  PRINTF("Allocating molecular memory: %g Mbytes; Total memory: %g Mbytes\n",
      now_memory,(*tot_memory));

  mdatom_maps->nmol_jmol_typ  = 
    (int *)cmalloc(nmol_typ*sizeof(int),"control_mol_params")-1;
  mdatom_maps->mol_typ        = 
    (NAME *)cmalloc(nmol_typ*sizeof(NAME),"control_mol_params")-1;
  mdatom_maps->nres_1mol_jmol_typ  = 
    (int *)cmalloc(nmol_typ*sizeof(int),"control_mol_params")-1;
  mdatom_maps->jres_jmol_typ_strt  = 
    (int *)cmalloc(nmol_typ*sizeof(int),"control_mol_params")-1;
  class_parse->ionfo_opt         = 
    (int *)cmalloc(nmol_typ*sizeof(int),"control_mol_params")-1;
  class_parse->ires_bond_conv    = 
    (int *)cmalloc(nmol_typ*sizeof(int),"control_mol_params")-1;
  class_parse->tau_nhc_mol       = 
    (double*)cmalloc(nmol_typ*sizeof(double),"control_mol_params")-1;
  class_parse->text_nhc_mol      = 
    (double*)cmalloc(nmol_typ*sizeof(double),"control_mol_params")-1;
  class_parse->imol_nhc_opt      = 
    (int *)cmalloc(nmol_typ*sizeof(int),"control_mol_params")-1;  
  class_parse->mol_freeze_opt    = 
    (int *)cmalloc(nmol_typ*sizeof(int),"control_mol_params")-1;  
  class_parse->mol_hydrog_mass_opt = 
    (int *)cmalloc(nmol_typ*sizeof(int),"control_mol_params")-1;
  class_parse->mol_hydrog_mass_val = 
    (double *)cmalloc(nmol_typ*sizeof(double),"control_mol_params")-1;
  class_parse->mol_hydrog_con_opt= 
    (int *)cmalloc(nmol_typ*sizeof(int),"control_mol_params")-1;
  filename_parse->mol_param_name = 
    (NAME *)cmalloc(nmol_typ*sizeof(NAME),"control_mol_params")-1;
  filename_parse->user_intra_name= 
    (NAME *)cmalloc(num_user*sizeof(NAME),"control_mol_params")-1;
  filename_parse->def_intra_name = 
    (NAME *)cmalloc(num_def*sizeof(NAME),"control_mol_params")-1;
  if(bond_free_num>0){
    mdintra->mdbond_free.file       = 
      (char *)cmalloc(MAXWORD*sizeof(char),"control_mol_params");
    free_parse->imoltyp_bond_free= 
      (int *) cmalloc(2*sizeof(int),"control_mol_params")-1;
    free_parse->imol_bond_free   = 
      (int *) cmalloc(2*sizeof(int),"control_mol_params")-1;
    free_parse->ires_bond_free   = 
      (int *) cmalloc(2*sizeof(int),"control_mol_params")-1;
    free_parse->iatm_bond_free   = 
      (int *) cmalloc(2*sizeof(int),"control_mol_params")-1;
  }
  if(bend_free_num>0){
    mdintra->mdbend_free.file       = 
      (char *)cmalloc(MAXWORD*sizeof(char),"control_mol_params");
    free_parse->imoltyp_bend_free= 
      (int *) cmalloc(3*sizeof(int),"control_mol_params")-1;
    free_parse->imol_bend_free   = 
      (int *) cmalloc(3*sizeof(int),"control_mol_params")-1;
    free_parse->ires_bend_free   = 
      (int *) cmalloc(3*sizeof(int),"control_mol_params")-1;
    free_parse->iatm_bend_free   = 
      (int *) cmalloc(3*sizeof(int),"control_mol_params")-1;
  }
  if(tors_free_num>0){
    mdintra->mdtors_free.file       = 
      (char *)cmalloc(MAXWORD*sizeof(char),"control_mol_params");
    free_parse->imoltyp_tors_free= 
      (int *) cmalloc(8*sizeof(int),"control_mol_params")-1;
    free_parse->imol_tors_free   = 
      (int *) cmalloc(8*sizeof(int),"control_mol_params")-1;
    free_parse->ires_tors_free   = 
      (int *) cmalloc(8*sizeof(int),"control_mol_params")-1;
    free_parse->iatm_tors_free   = 
      (int *) cmalloc(8*sizeof(int),"control_mol_params")-1;
  }

  if(rbar_sig_free_iopt>0){
    mdintra->mdrbar_sig_free.file   = 
      (char *)cmalloc(MAXWORD*sizeof(char),"control_mol_params");
  }
  mdclatoms_info->text_mol   = 
    (double*)cmalloc(nmol_typ*sizeof(double),"control_mol_params")-1;

  text_mol       = mdclatoms_info->text_mol;
  text_nhc_mol   = class_parse->text_nhc_mol;
  mol_freeze_opt = class_parse->mol_freeze_opt;
  imol_nhc_opt   = class_parse->imol_nhc_opt;

  /*========================================================================*/
  /* IV) Get molecular/CP setup information */

  control_set_mol_params(mdatom_maps,&(cp->cpopts),
      &(cp->cpcoeffs_info),cp_parse,class_parse,
      mdintra,mdsurface,
      filename_parse,free_parse,
      &dict_mol,word,
      fun_key,&nfun_key,iextend,
      general_data->genstatepoint.t_ext,
      ifirst,pi_beads);
  if(tors_free_num==1){
    tors_free_num = mdintra->mdtors_free.num; /* changed in above routine */
  }/*endif*/

  for(i=1; i<= nmol_typ; i++){
    text_mol[i] = text_nhc_mol[i];   
  }/*endfor*/

  /*========================================================================*/
  /* V) Free some memory and malloc some other                              */

  if(bond_free_num>0){
    nhist = (mdintra->mdbond_free.nhist);
    mdintra->mdbond_free.hist = 
      (double *)cmalloc(nhist*sizeof(double),"control_mol_params")-1;
  }/*endif*/

  if(bend_free_num>0){
    nhist = (mdintra->mdbend_free.nhist);
    mdintra->mdbend_free.hist = 
      (double *)cmalloc(nhist*sizeof(double),"control_mol_params")-1;
  }/*endif*/

  if(tors_free_num==1){
    nhist = (mdintra->mdtors_free.nhist);
    mdintra->mdtors_free.hist = 
      (double *)cmalloc(nhist*sizeof(double),"control_mol_params")-1;
  }/*endif*/
  if(tors_free_num==2){
    nhist = (mdintra->mdtors_free.nhist);
    mdintra->mdtors_free.hist_2d = cmall_mat(1,nhist,1,nhist,"control_mol_params");
  }/*endif*/

  if(rbar_sig_free_iopt>0){
    nhist_bar = (mdintra->mdrbar_sig_free.nhist_bar);
    nhist_sig = (mdintra->mdrbar_sig_free.nhist_sig);
    nfree     = (mdintra->mdrbar_sig_free.nfree);
    mdintra->mdrbar_sig_free.hist    = 
      cmall_mat(1,nhist_bar,1,nhist_sig,"control_mol_params");
    mdintra->mdrbar_sig_free.hist_rn = 
      cmall_mat(1,nfree,1,nhist_bar,"control_mol_params");
  }/*endif*/

  cfree(fun_key,"control_mol_params");
  cfree(word,"control_mol_params");
  cfree(&dict_mol.fun_dict[1],"control_mol_params");
  cfree(&dict_mol.mol_dict[1],"control_mol_params");
  cfree(&dict_mol.wave_dict[1],"control_mol_params");
  cfree(&dict_mol.bond_free_dict[1],"control_mol_params");
  cfree(&dict_mol.bend_free_dict[1],"control_mol_params");
  cfree(&dict_mol.tors_free_dict[1],"control_mol_params");
  cfree(&dict_mol.rbar_free_dict[1],"control_mol_params");
  cfree(&dict_mol.user_base_dict[1],"control_mol_params");
  cfree(&dict_mol.def_base_dict[1],"control_mol_params");

  for(jmol_typ=1;jmol_typ<=nmol_typ;jmol_typ++){

    if((mol_freeze_opt[jmol_typ] > 0) &&  (ipress > 0)){
      PRINTF("@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
      PRINTF("No freezing allowed with NPT_I and NPT_F       \n");
      PRINTF("Ensembles                                      \n");
      PRINTF("@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
      FFLUSH(stdout);
      EXIT(1);
    }/*endif*/

    if((mol_freeze_opt[jmol_typ]==1)&&(imol_nhc_opt[jmol_typ] > 0)){
      PRINTF("@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
      PRINTF("Do not use thermostating when freezing the     \n");
      PRINTF("whole molecule.(Use none option)               \n");
      PRINTF("@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
      FFLUSH(stdout);
      EXIT(1);
    }/*endif*/

  }/*endfor*/

  /*========================================================================*/
  /* Error check */

  nmol_tot = 0;
  nmol_jmol_typ  = mdatom_maps->nmol_jmol_typ;
  for(i=1;i<=nmol_typ;i++){nmol_tot+= nmol_jmol_typ[i];}

  if(cp_on==1 && cp->cpopts.cp_dual_grid_opt >= 1){
    if(cp_parse->cp_ecut_dual_grid > cp_parse->cp_ecut){
      PRINTF("@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");   
      PRINTF("The small dense grid cutoff is less than the large sparse");
      PRINTF("grid cutoff. This might work, but I doubut it\n");
      PRINTF("@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
      FFLUSH(stdout);
      EXIT(1);
    }
  }

  /*========================================================================*/
  /* VI) Done                                                               */

  PRINTF("The class contains %d molecule types\n",nmol_typ);
  PRINTF("\n"); 

  PRINT_LINE_DASH;
  PRINTF("Completed reading molecular set up file %s\n",molsetname);
  PRINT_LINE_STAR;
  PRINTF("\n");

  /*------------------------------------------------------------------------*/
}/*end routine*/