NAMD
Public Member Functions | Public Attributes | List of all members
Parameters Class Reference

#include <Parameters.h>

Public Member Functions

 Parameters ()
 
 Parameters (SimParameters *, StringList *f)
 
 Parameters (Ambertoppar *, BigReal)
 
void read_parm (Ambertoppar *, BigReal)
 
 Parameters (AmberParm7Reader::Ambertoppar *, BigReal)
 
void read_parm (AmberParm7Reader::Ambertoppar *, BigReal)
 
 Parameters (const GromacsTopFile *gf, Bool min)
 
 ~Parameters ()
 
char * atom_type_name (Index a)
 
void read_parameter_file (char *)
 
void read_charmm_parameter_file (char *)
 
void done_reading_files (Bool)
 
void done_reading_structure ()
 
void assign_vdw_index (const char *, Atom *)
 
void assign_bond_index (const char *, const char *, Bond *, bool *bond_found=nullptr)
 
void assign_angle_index (const char *, const char *, const char *, Angle *, int)
 
void assign_dihedral_index (const char *, const char *, const char *, const char *, Dihedral *, int, int)
 
void assign_improper_index (const char *, const char *, const char *, const char *, Improper *, int)
 
void assign_crossterm_index (const char *, const char *, const char *, const char *, const char *, const char *, const char *, const char *, Crossterm *)
 
void send_Parameters (MOStream *)
 
void receive_Parameters (MIStream *)
 
void get_bond_params (Real *k, Real *x0, Index index)
 
void get_angle_params (Real *k, Real *theta0, Real *k_ub, Real *r_ub, Index index)
 
int get_improper_multiplicity (Index index)
 
int get_dihedral_multiplicity (Index index)
 
void get_improper_params (Real *k, int *n, Real *delta, Index index, int mult)
 
void get_dihedral_params (Real *k, int *n, Real *delta, Index index, int mult)
 
void get_vdw_params (Real *sigma, Real *epsilon, Real *sigma14, Real *epsilon14, Index index)
 
int get_vdw_pair_params (Index ind1, Index ind2, Real *, Real *, Real *, Real *)
 
int get_num_vdw_params (void)
 
int get_table_pair_params (Index, Index, int *)
 
void print_bond_params ()
 
void print_angle_params ()
 
void print_dihedral_params ()
 
void print_dihedral_array ()
 
void print_improper_params ()
 
void print_crossterm_params ()
 
void print_vdw_params ()
 
void print_vdw_pair_params ()
 
void print_nbthole_pair_params ()
 
void print_param_summary ()
 
void read_ener_table (SimParameters *)
 
int get_int_table_type (char *)
 
int read_energy_type (FILE *, const int, BigReal *, const float, const float)
 
int read_energy_type_cubspline (FILE *, const int, BigReal *, const float, const float)
 
int read_energy_type_bothcubspline (FILE *, const int, BigReal *, const float, const float)
 

Public Attributes

BondValuebond_array
 
AngleValueangle_array
 
DihedralValuedihedral_array
 
ImproperValueimproper_array
 
CrosstermValuecrossterm_array
 
GromacsPairValuegromacsPair_array
 
VdwValuevdw_array
 
NbtholePairValuenbthole_array
 
int numenerentries
 
int rowsize
 
int columnsize
 
BigRealtable_ener
 
IndexedVdwPairvdw_pair_tree
 
IndexedNbtholePairnbthole_pair_tree
 
IndexedTablePairtab_pair_tree
 
int tablenumtypes
 
int NumBondParams
 
int NumAngleParams
 
int NumCosAngles
 
int NumDihedralParams
 
int NumImproperParams
 
int NumCrosstermParams
 
int NumGromacsPairParams
 
int NumVdwParams
 
int NumTableParams
 
int NumVdwParamsAssigned
 
int NumVdwPairParams
 
int NumNbtholePairParams
 
int NumTablePairParams
 

Detailed Description

Definition at line 265 of file Parameters.h.

Constructor & Destructor Documentation

◆ Parameters() [1/5]

Parameters::Parameters ( )

Definition at line 193 of file Parameters.C.

193  {
194  initialize();
195 }

◆ Parameters() [2/5]

Parameters::Parameters ( SimParameters simParams,
StringList f 
)

Definition at line 264 of file Parameters.C.

References StringList::data, done_reading_files(), FALSE, StringList::next, paraCharmm, paraXplor, read_charmm_parameter_file(), read_ener_table(), read_parameter_file(), and simParams.

265 {
266  initialize();
267 
269  if (simParams->paraTypeXplorOn)
270  {
271  paramType = paraXplor;
272  }
273  else if (simParams->paraTypeCharmmOn)
274  {
275  paramType = paraCharmm;
276  }
277  //****** END CHARMM/XPLOR type changes
278  //Test for cos-based angles
279  if (simParams->cosAngles) {
280  cosAngles = true;
281  } else {
282  cosAngles = false;
283  }
284 
285  if (simParams->tabulatedEnergies) {
286  CkPrintf("Working on tables\n");
288  }
289 #ifdef ACCELERATED_INPUT
290  if(simParams->genCompressedPsf || simParams->useCompressedPsf)
291  {
292  // Compressed PSF relies on strict alpha ordering
293  strictSort=true;
294  } else {
295  strictSort=false;
296  }
297 #endif
298 #ifdef DEBUGM
299  strictSort=true;
300 #endif
301  //****** BEGIN CHARMM/XPLOR type changes
302  /* Set up AllFilesRead flag to FALSE. Once all of the files */
303  /* have been read in, then this will be set to true and the */
304  /* arrays of parameters will be set up */
305  AllFilesRead = FALSE;
306 
307  if (NULL != f)
308  {
309  do
310  {
311  //****** BEGIN CHARMM/XPLOR type changes
312  if (paramType == paraXplor)
313  {
315  }
316  else if (paramType == paraCharmm)
317  {
319  }
320  //****** END CHARMM/XPLOR type changes
321  f = f->next;
322  } while ( f != NULL );
323 
324  done_reading_files(simParams->drudeOn && paramType == paraCharmm);
325  }
326 
327 }
#define paraCharmm
Definition: Parameters.h:97
void read_charmm_parameter_file(char *)
Definition: Parameters.C:567
#define FALSE
Definition: common.h:127
void read_parameter_file(char *)
Definition: Parameters.C:430
void done_reading_files(Bool)
Definition: Parameters.C:3813
#define simParams
Definition: Output.C:129
StringList * next
Definition: ConfigList.h:49
char * data
Definition: ConfigList.h:48
#define paraXplor
Definition: Parameters.h:96
void read_ener_table(SimParameters *)
Definition: Parameters.C:8527

◆ Parameters() [3/5]

Parameters::Parameters ( Ambertoppar amber_data,
BigReal  vdw14 
)

Definition at line 7977 of file Parameters.C.

7978 {
7979  initialize();
7980 
7981  // Read in parm parameters
7982  read_parm(amber_data,vdw14);
7983 }

◆ Parameters() [4/5]

Parameters::Parameters ( AmberParm7Reader::Ambertoppar amber_data,
BigReal  vdw14 
)

Definition at line 8114 of file Parameters.C.

8115 {
8116  initialize();
8117 
8118  // Read in parm parameters
8119  read_parm(amber_data,vdw14);
8120 }

◆ Parameters() [5/5]

Parameters::Parameters ( const GromacsTopFile gf,
Bool  min 
)

Definition at line 8285 of file Parameters.C.

8286 {
8287  initialize();
8288 
8289  // Read in parm parameters
8290  read_parm(gf,min);
8291 }

◆ ~Parameters()

Parameters::~Parameters ( )

Definition at line 339 of file Parameters.C.

References angle_array, bond_array, crossterm_array, dihedral_array, gromacsPair_array, improper_array, nbthole_pair_tree, ResizeArray< Elem >::resize(), ResizeArray< Elem >::size(), tab_pair_tree, vdw_array, and vdw_pair_tree.

341 {
342  if (atomTypeNames)
343  delete [] atomTypeNames;
344 
345  if (bondp != NULL)
346  free_bond_tree(bondp);
347 
348  if (anglep != NULL)
349  free_angle_tree(anglep);
350 
351  if (dihedralp != NULL)
352  free_dihedral_list(dihedralp);
353 
354  if (improperp != NULL)
355  free_improper_list(improperp);
356 
357  if (crosstermp != NULL)
358  free_crossterm_list(crosstermp);
359 
360  if (vdwp != NULL)
361  free_vdw_tree(vdwp);
362 
363  if (vdw_pairp != NULL)
364  free_vdw_pair_list();
365 
366  if (nbthole_pairp != NULL)
367  free_nbthole_pair_list();
368 
369  if (bond_array != NULL)
370  delete [] bond_array;
371 
372  if (angle_array != NULL)
373  delete [] angle_array;
374 
375  if (dihedral_array != NULL)
376  delete [] dihedral_array;
377 
378  if (improper_array != NULL)
379  delete [] improper_array;
380 
381  if (crossterm_array != NULL)
382  delete [] crossterm_array;
383 
384  // JLai
385  if (gromacsPair_array != NULL)
386  delete [] gromacsPair_array;
387  // End of JLai
388 
389  if (vdw_array != NULL)
390  delete [] vdw_array;
391 
392  if (tab_pair_tree != NULL)
393  free_table_pair_tree(tab_pair_tree);
394 
395  if (vdw_pair_tree != NULL)
396  free_vdw_pair_tree(vdw_pair_tree);
397 
398  if (nbthole_pair_tree != NULL)
399  free_nbthole_pair_tree(nbthole_pair_tree);
400 
401  if (maxDihedralMults != NULL)
402  delete [] maxDihedralMults;
403 
404  if (maxImproperMults != NULL)
405  delete [] maxImproperMults;
406 
407  for( int i = 0; i < error_msgs.size(); ++i ) {
408  delete [] error_msgs[i];
409  }
410  error_msgs.resize(0);
411 }
GromacsPairValue * gromacsPair_array
Definition: Parameters.h:318
int size(void) const
Definition: ResizeArray.h:131
DihedralValue * dihedral_array
Definition: Parameters.h:314
CrosstermValue * crossterm_array
Definition: Parameters.h:316
IndexedVdwPair * vdw_pair_tree
Definition: Parameters.h:326
void resize(int i)
Definition: ResizeArray.h:84
IndexedNbtholePair * nbthole_pair_tree
Definition: Parameters.h:327
AngleValue * angle_array
Definition: Parameters.h:313
ImproperValue * improper_array
Definition: Parameters.h:315
VdwValue * vdw_array
Definition: Parameters.h:320
BondValue * bond_array
Definition: Parameters.h:312
IndexedTablePair * tab_pair_tree
Definition: Parameters.h:328

Member Function Documentation

◆ assign_angle_index()

void Parameters::assign_angle_index ( const char *  atom1,
const char *  atom2,
const char *  atom3,
Angle angle_ptr,
int  notFoundIndex 
)

Definition at line 4849 of file Parameters.C.

References angle::angle_type, angle::atom1, angle_params::atom1name, angle::atom2, angle_params::atom2name, angle::atom3, angle_params::atom3name, endi(), angle_params::index, TwoLevelParam< NumStrings, ParamValue >::index(), iout, iWARN(), and NAMD_die().

4852 {
4853  struct angle_params *ptr; // Current position in tree
4854  int comp_val; // value from strcasecmp
4855  int found=0; // flag 1->found a match
4856 
4857  /* Check to make sure the files have all been read */
4858  if (!AllFilesRead)
4859  {
4860  NAMD_die("Tried to assign angle index before all parameter files were read");
4861  }
4862 
4863  /* We need atom1 < atom3. If that was not what we were */
4864  /* passed, switch them */
4865  if (strcasecmp(atom1, atom3) > 0)
4866  {
4867  const char *tmp_name = atom1;
4868  atom1 = atom3;
4869  atom3 = tmp_name;
4870  }
4871 
4872 #ifndef ACCELERATED_INPUT_ANGLES
4873  /* Start at the top */
4874  ptr=anglep;
4875 
4876  /* While we don't have a match and we haven't reached the */
4877  /* bottom of the tree, compare values */
4878  while (!found && (ptr != NULL))
4879  {
4880  comp_val = strcasecmp(atom1, ptr->atom1name);
4881 
4882  if (comp_val == 0)
4883  {
4884  /* Atom 1 matches, so compare atom 2 */
4885  comp_val = strcasecmp(atom2, ptr->atom2name);
4886 
4887  if (comp_val == 0)
4888  {
4889  /* Atoms 1&2 match, try atom 3 */
4890  comp_val = strcasecmp(atom3, ptr->atom3name);
4891  }
4892  }
4893 
4894  if (comp_val == 0)
4895  {
4896  /* Found a match */
4897  found = 1;
4898  angle_ptr->angle_type = ptr->index;
4899  }
4900  else if (comp_val < 0)
4901  {
4902  /* Go left */
4903  ptr=ptr->left;
4904  }
4905  else
4906  {
4907  /* Go right */
4908  ptr=ptr->right;
4909  }
4910  }
4911 #else
4912  TupleString3 searchFor(atom1,atom2,atom3);
4913  int64_t result = anglemap->index(searchFor);
4914  if(result >= 0)
4915  {
4916  found=true;
4917  angle_ptr->angle_type = result;
4918  }
4919 
4920 #endif
4921  /* Make sure we found a match */
4922  if (!found)
4923  {
4924  char err_msg[512];
4925 
4926  snprintf(err_msg, sizeof(err_msg),
4927  "UNABLE TO FIND ANGLE PARAMETERS FOR %s %s %s (ATOMS %i %i %i)",
4928  atom1, atom2, atom3,
4929  angle_ptr->atom1+1, angle_ptr->atom2+1, angle_ptr->atom3+1);
4930  if ( notFoundIndex ) {
4931  angle_ptr->angle_type = notFoundIndex;
4932  iout << iWARN << err_msg << "\n" << endi;
4933  return;
4934  } else NAMD_die(err_msg);
4935  }
4936 
4937  return;
4938 }
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
std::ostream & iWARN(std::ostream &s)
Definition: InfoStream.C:82
#define iout
Definition: InfoStream.h:51
char atom3name[11]
Definition: Parameters.C:65
int32 atom2
Definition: structures.h:58
int32 atom1
Definition: structures.h:57
int32 atom3
Definition: structures.h:59
char atom1name[11]
Definition: Parameters.C:63
void NAMD_die(const char *err_msg)
Definition: common.C:147
Index angle_type
Definition: structures.h:60
Index index
Definition: Parameters.C:71
char atom2name[11]
Definition: Parameters.C:64
int64_t const index(const TupleString< NumStrings > &findKey) const
Definition: TupleString.h:340

◆ assign_bond_index()

void Parameters::assign_bond_index ( const char *  atom1,
const char *  atom2,
Bond bond_ptr,
bool *  bond_found = nullptr 
)

Definition at line 4741 of file Parameters.C.

References bond::atom1, bond_params::atom1name, bond::atom2, bond_params::atom2name, bond::bond_type, bond_params::index, TwoLevelParam< NumStrings, ParamValue >::index(), and NAMD_die().

4743 {
4744  struct bond_params *ptr; // Current location in tree
4745  int found=0; // Flag 1-> found a match
4746  int cmp_code; // return code from strcasecmp
4747 
4748  /* Check to make sure the files have all been read */
4749  if (!AllFilesRead)
4750  {
4751  NAMD_die("Tried to assign bond index before all parameter files were read");
4752  }
4753 
4754  /* We need atom1 < atom2, so if that's not the way they */
4755  /* were passed, flip them */
4756  if (strcasecmp(atom1, atom2) > 0)
4757  {
4758  const char *tmp_name = atom1;
4759  atom1 = atom2;
4760  atom2 = tmp_name;
4761  }
4762 #ifndef ACCELERATED_INPUT
4763  /* Start at the top */
4764  ptr=bondp;
4765 
4766  /* While we haven't found a match and we're not at the end */
4767  /* of the tree, compare the bond passed in with the tree */
4768  while (!found && (ptr!=NULL))
4769  {
4770  cmp_code=strcasecmp(atom1, ptr->atom1name);
4771 
4772  if (cmp_code == 0)
4773  {
4774  cmp_code=strcasecmp(atom2, ptr->atom2name);
4775  }
4776 
4777  if (cmp_code == 0)
4778  {
4779  /* Found a match */
4780  found=1;
4781  bond_ptr->bond_type = ptr->index;
4782  }
4783  else if (cmp_code < 0)
4784  {
4785  /* Go left */
4786  ptr=ptr->left;
4787  }
4788  else
4789  {
4790  /* Go right */
4791  ptr=ptr->right;
4792  }
4793  }
4794 #else
4795  TupleString2 searchFor(atom1,atom2);
4796  int64_t result= bondmap->index(searchFor);
4797  if(result>=0)
4798  {
4799  found=true;
4800  bond_ptr->bond_type = result;
4801  }
4802 #endif
4803  /* Check to see if we found anything */
4804  if (!found)
4805  {
4806  if ((strcmp(atom1, "DRUD")==0 || strcmp(atom2, "DRUD")==0)
4807  && (strcmp(atom1, "X")!=0 && strcmp(atom2, "X")!=0)) {
4808  /* try a wildcard DRUD X match for this Drude bond */
4809  char a1[8] = "DRUD", a2[8] = "X";
4810  return assign_bond_index(a1, a2, bond_ptr, bond_found); /* recursive call */
4811  }
4812  else if (bond_found == nullptr) {
4813  char err_msg[512];
4814 
4815  snprintf(err_msg, sizeof(err_msg),
4816  "UNABLE TO FIND BOND PARAMETERS FOR %s %s (ATOMS %i %i)",
4817  atom1, atom2, bond_ptr->atom1+1, bond_ptr->atom2+1);
4818  NAMD_die(err_msg);
4819  }
4820  }
4821  if (bond_found != nullptr) {
4822  *bond_found = bool(found);
4823  }
4824 
4825  return;
4826 }
Index index
Definition: Parameters.C:50
void assign_bond_index(const char *, const char *, Bond *, bool *bond_found=nullptr)
Definition: Parameters.C:4741
int32 atom1
Definition: structures.h:50
char atom1name[11]
Definition: Parameters.C:46
void NAMD_die(const char *err_msg)
Definition: common.C:147
char atom2name[11]
Definition: Parameters.C:47
int64_t const index(const TupleString< NumStrings > &findKey) const
Definition: TupleString.h:340
Index bond_type
Definition: structures.h:52
int32 atom2
Definition: structures.h:51

◆ assign_crossterm_index()

void Parameters::assign_crossterm_index ( const char *  atom1,
const char *  atom2,
const char *  atom3,
const char *  atom4,
const char *  atom5,
const char *  atom6,
const char *  atom7,
const char *  atom8,
Crossterm crossterm_ptr 
)

Definition at line 5352 of file Parameters.C.

References crossterm::atom1, crossterm_params::atom1name, crossterm::atom2, crossterm_params::atom2name, crossterm::atom3, crossterm_params::atom3name, crossterm::atom4, crossterm_params::atom4name, crossterm::atom5, crossterm_params::atom5name, crossterm::atom6, crossterm_params::atom6name, crossterm::atom7, crossterm_params::atom7name, crossterm::atom8, crossterm_params::atom8name, crossterm::crossterm_type, crossterm_params::index, TwoLevelParam< NumStrings, ParamValue >::index(), NAMD_die(), and crossterm_params::next.

5355 {
5356  int found=0; // Flag 1->found a match
5357 #ifndef ACCELERATED_INPUT_CROSSTERMS
5358  struct crossterm_params *ptr; // Current position in list
5359 
5360  /* Start at the head of the list */
5361  ptr=crosstermp;
5362 
5363  /* While we haven't fuond a match and haven't reached the end */
5364  /* of the list, keep looking */
5365  while (!found && (ptr!=NULL))
5366  {
5367  /* Do a linear search through the linked list of */
5368  /* crossterm parameters. Since the list is arranged */
5369  /* with wildcard paramters at the end of the list, we */
5370  /* can simply do a linear search and be guaranteed that*/
5371  /* we will find exact matches before wildcard matches. */
5372  /* Also, we must check for an exact match, and a match */
5373  /* in reverse, since they are really the same */
5374  /* physically. */
5375  if ( ( (strcasecmp(ptr->atom1name, atom1)==0) ||
5376  (strcasecmp(ptr->atom1name, "X")==0) ) &&
5377  ( (strcasecmp(ptr->atom2name, atom2)==0) ||
5378  (strcasecmp(ptr->atom2name, "X")==0) ) &&
5379  ( (strcasecmp(ptr->atom3name, atom3)==0) ||
5380  (strcasecmp(ptr->atom3name, "X")==0) ) &&
5381  ( (strcasecmp(ptr->atom4name, atom4)==0) ||
5382  (strcasecmp(ptr->atom4name, "X")==0) ) )
5383  {
5384  /* Found an exact match */
5385  found=1;
5386  }
5387  else if ( ( (strcasecmp(ptr->atom4name, atom1)==0) ||
5388  (strcasecmp(ptr->atom4name, "X")==0) ) &&
5389  ( (strcasecmp(ptr->atom3name, atom2)==0) ||
5390  (strcasecmp(ptr->atom3name, "X")==0) ) &&
5391  ( (strcasecmp(ptr->atom2name, atom3)==0) ||
5392  (strcasecmp(ptr->atom2name, "X")==0) ) &&
5393  ( (strcasecmp(ptr->atom1name, atom4)==0) ||
5394  (strcasecmp(ptr->atom1name, "X")==0) ) )
5395  {
5396  /* Found a reverse match */
5397  found=1;
5398  }
5399  if ( ! found ) {
5400  /* Didn't find a match, go to the next node */
5401  ptr=ptr->next;
5402  continue;
5403  }
5404  found = 0;
5405  if ( ( (strcasecmp(ptr->atom5name, atom5)==0) ||
5406  (strcasecmp(ptr->atom5name, "X")==0) ) &&
5407  ( (strcasecmp(ptr->atom6name, atom6)==0) ||
5408  (strcasecmp(ptr->atom6name, "X")==0) ) &&
5409  ( (strcasecmp(ptr->atom7name, atom7)==0) ||
5410  (strcasecmp(ptr->atom7name, "X")==0) ) &&
5411  ( (strcasecmp(ptr->atom8name, atom8)==0) ||
5412  (strcasecmp(ptr->atom8name, "X")==0) ) )
5413  {
5414  /* Found an exact match */
5415  found=1;
5416  }
5417  else if ( ( (strcasecmp(ptr->atom8name, atom5)==0) ||
5418  (strcasecmp(ptr->atom8name, "X")==0) ) &&
5419  ( (strcasecmp(ptr->atom7name, atom6)==0) ||
5420  (strcasecmp(ptr->atom7name, "X")==0) ) &&
5421  ( (strcasecmp(ptr->atom6name, atom7)==0) ||
5422  (strcasecmp(ptr->atom6name, "X")==0) ) &&
5423  ( (strcasecmp(ptr->atom5name, atom8)==0) ||
5424  (strcasecmp(ptr->atom5name, "X")==0) ) )
5425  {
5426  /* Found a reverse match */
5427  found=1;
5428  }
5429  if ( ! found ) {
5430  /* Didn't find a match, go to the next node */
5431  ptr=ptr->next;
5432  }
5433  }
5434 #else
5435  /* We set a canonical order so ABCD==DCBA for each term and for the pair of terms
5436  and for typical (XBCX) wildcard cases */
5437  int cmp11 = strcasecmp(atom1, atom4);
5438  int cmp12 = strcasecmp(atom2, atom3);
5439  int cmp21 = strcasecmp(atom5, atom8);
5440  int cmp22 = strcasecmp(atom6, atom7);
5441 
5442 
5443  int reverseBits= (cmp21==0) ? ( (cmp22 >0 ) ? 0x1 : 0x0 ) : ((cmp21>0) ? 0x1 : 0x0);
5444  int reverseBits2= (cmp11==0) ? ( (cmp12 >0 ) ? 0x10 : 0x00 ) : ((cmp11>0) ? 0x10 : 0x00);
5445  int cmpo1 = ( reverseBits) ? strcasecmp(atom4, atom8) : strcasecmp(atom1, atom5);
5446  int cmpo2 = (reverseBits2 ) ? strcasecmp(atom3, atom7) : strcasecmp(atom2, atom6);
5447  static const short o1order1order2=0x000;
5448  static const short r1order1order2=0x100;
5449  static const short o1order1reverse2=0x001;
5450  static const short r1order1reverse2=0x101;
5451  static const short o1reverse1order2=0x010;
5452  static const short r1reverse1order2=0x110;
5453  static const short o1reverse1reverse2=0x011;
5454  static const short r1reverse1reverse2=0x111;
5455  int reverseBits3= (cmpo1==0) ? ( (cmpo2 >0 ) ? 0x100 : 0x000 ) : ((cmpo1>0) ? 0x100 : 0x000);
5456  reverseBits|=reverseBits2 | reverseBits3;
5457  TupleString8 searchFor;
5458  switch (reverseBits)
5459  {
5460  case o1order1order2:
5461  searchFor = TupleString8(atom1, atom2, atom3, atom4,
5462  atom5, atom6, atom7, atom8);
5463  break;
5464  case o1order1reverse2:
5465  searchFor = TupleString8(atom1, atom2, atom3, atom4,
5466  atom8, atom7, atom6, atom5);
5467  break;
5468  case o1reverse1order2:
5469  searchFor = TupleString8(atom4, atom3, atom2, atom1,
5470  atom5, atom6, atom7, atom8);
5471  break;
5472  case o1reverse1reverse2:
5473  searchFor = TupleString8(atom4, atom3, atom2, atom1,
5474  atom8, atom7, atom6, atom5);
5475  break;
5476  case r1order1order2:
5477  searchFor = TupleString8(atom5, atom6, atom7, atom8,
5478  atom1, atom2, atom3, atom4);
5479  break;
5480  case r1order1reverse2:
5481  searchFor = TupleString8(atom8, atom7, atom6, atom5,
5482  atom1, atom2, atom3, atom4);
5483  break;
5484  case r1reverse1order2:
5485  searchFor = TupleString8(atom5, atom6, atom7, atom8,
5486  atom4, atom3, atom2, atom1);
5487  break;
5488  case r1reverse1reverse2:
5489  searchFor = TupleString8(atom8, atom7, atom6, atom5,
5490  atom4, atom3, atom2, atom1);
5491  break;
5492  default:
5493  NAMD_die("invalid crossterm ordering value");
5494  }
5495 
5496  int64_t result = crosstermmap->index(searchFor);
5497  if(result >=0 )
5498  {
5499  found=true;
5500  crossterm_ptr->crossterm_type = result;
5501  }
5502  if (!found) // check for wild cards
5503  {
5504  TupleString8 searchForW[6];
5505  switch (reverseBits)
5506  {
5507  case o1order1order2 :
5508  searchForW[0] = TupleString8("X", atom2, atom3, atom4, atom5, atom6, atom7, "X");
5509  searchForW[1] = TupleString8(atom1, "X", atom3, atom4, atom5, atom6, "X", atom8);
5510  searchForW[2] = TupleString8(atom1, atom2, "X", atom4, atom5, "X", atom7, atom8);
5511  searchForW[3] = TupleString8(atom1, atom2, atom3, "X", "X", atom6, atom7, atom8);
5512  searchForW[4] = TupleString8("X", atom2, atom3, "X", "X", atom6, atom7, "X");
5513  searchForW[5] = TupleString8(atom1,"X", "X", atom4, atom5, "X", "X", atom8);
5514  break;
5515  case o1order1reverse2 :
5516  searchForW[0] = TupleString8("X", atom2, atom3, atom4, atom8, atom7, atom6, "X");
5517  searchForW[1] = TupleString8(atom1, "X", atom3, atom4, atom8, atom7, "X", atom5);
5518  searchForW[2] = TupleString8(atom1, atom2, "X", atom4, atom8, "X", atom6, atom5);
5519  searchForW[3] = TupleString8(atom1, atom2, atom3, "X", "X", atom7, atom6, atom5);
5520  searchForW[4] = TupleString8("X", atom2, atom3, "X", "X", atom7, atom6, "X");
5521  searchForW[5] = TupleString8(atom1,"X", "X", atom4, atom8, "X", "X", atom5);
5522  break;
5523  case o1reverse1order2 :
5524  searchForW[0] = TupleString8("X", atom3, atom2, atom1, atom5, atom6, atom7, "X");
5525  searchForW[1] = TupleString8(atom4, "X", atom2, atom1, atom5, atom6, "X", atom8);
5526  searchForW[2] = TupleString8(atom4, atom3, "X", atom1, atom5, "X", atom7, atom8);
5527  searchForW[3] = TupleString8(atom4, atom3, atom2, "X", "X", atom6, atom7, atom8);
5528  searchForW[4] = TupleString8("X", atom3, atom2, "X", "X", atom6, atom7, "X");
5529  searchForW[5] = TupleString8(atom4,"X", "X", atom1, atom5, "X", "X", atom8);
5530  break;
5531  case o1reverse1reverse2 :
5532  searchForW[0] = TupleString8("X", atom3, atom2, atom1, atom8, atom7, atom6, "X");
5533  searchForW[1] = TupleString8(atom4, "X", atom2, atom1, atom8, atom7, "X", atom5);
5534  searchForW[2] = TupleString8(atom4, atom3, "X", atom1, atom8, "X", atom6, atom5);
5535  searchForW[3] = TupleString8(atom4, atom3, atom2, "X", "X", atom7, atom6, atom5);
5536  searchForW[4] = TupleString8("X", atom3, atom2, "X", "X", atom7, atom6, "X");
5537  searchForW[5] = TupleString8(atom4,"X", "X", atom1, atom8, "X", "X", atom5);
5538  break;
5539  case r1reverse1reverse2:
5540  searchForW[0] = TupleString8("X", atom7, atom6, atom5, atom4, atom3, atom2, "X");
5541  searchForW[1] = TupleString8(atom8, "X", atom6, atom5, atom4, atom3, "X", atom1);
5542  searchForW[2] = TupleString8(atom8, atom7, "X", atom5, atom4, "X", atom2, atom1);
5543  searchForW[3] = TupleString8(atom8, atom7, atom6, "X", "X", atom3, atom2, atom1);
5544  searchForW[4] = TupleString8("X", atom7, atom6, "X", "X", atom3, atom2, "X");
5545  searchForW[5] = TupleString8(atom8, "X", "X", atom5, atom4, "X", "X", atom1);
5546  break;
5547  case r1reverse1order2:
5548  searchForW[0] = TupleString8("X", atom7, atom6, atom5, atom1, atom2, atom3, "X");
5549  searchForW[1] = TupleString8(atom8, "X", atom6, atom5, atom1, atom2, "X", atom4);
5550  searchForW[2] = TupleString8(atom8, atom7, "X", atom5, atom1, "X", atom3, atom4);
5551  searchForW[3] = TupleString8(atom8, atom7, atom6, "X", "X", atom2, atom3, atom4);
5552  searchForW[4] = TupleString8("X", atom7, atom6, "X", "X", atom2, atom3, "X");
5553  searchForW[5] = TupleString8(atom8, "X", "X", atom5, atom1, "X", "X", atom4);
5554  break;
5555  case r1order1reverse2:
5556  searchForW[0] = TupleString8("X", atom6, atom7, atom8, atom4, atom3, atom2, "X");
5557  searchForW[1] = TupleString8(atom5, "X", atom7, atom8, atom4, atom3, "X", atom1);
5558  searchForW[2] = TupleString8(atom5, atom6, "X", atom8, atom4, "X", atom2, atom1);
5559  searchForW[3] = TupleString8(atom5, atom6, atom7, "X", "X", atom3, atom2, atom1);
5560  searchForW[4] = TupleString8("X", atom6, atom7, "X", "X", atom3, atom2, "X");
5561  searchForW[5] = TupleString8(atom5, "X", "X", atom8, atom4, "X", "X", atom1);
5562  break;
5563  default:
5564  NAMD_die("invalid reverse key order for crossterms");
5565  }
5566  for(int i=0; i<7; ++i)
5567  {
5568  result = crosstermmap->index(searchForW[i]);
5569  if(result >= 0)
5570  {
5571  found=true;
5572  crossterm_ptr->crossterm_type = result;
5573  break;
5574  }
5575  }
5576  }
5577 #endif
5578 
5579  /* Make sure we found a match */
5580  if (!found)
5581  {
5582  char err_msg[512];
5583 
5584  snprintf(err_msg, sizeof(err_msg),
5585  "UNABLE TO FIND CROSSTERM PARAMETERS FOR "
5586  "%s %s %s %s %s %s %s %s\n"
5587  "(ATOMS %i %i %i %i %i %i %i %i)",
5588  atom1, atom2, atom3, atom4, atom5, atom6, atom7, atom8,
5589  crossterm_ptr->atom1+1, crossterm_ptr->atom2+1,
5590  crossterm_ptr->atom3+1, crossterm_ptr->atom4+1,
5591  crossterm_ptr->atom5+1, crossterm_ptr->atom6+1,
5592  crossterm_ptr->atom7+1, crossterm_ptr->atom8+1);
5593 
5594  NAMD_die(err_msg);
5595  }
5596 
5597 #ifndef ACCELERATED_INPUT_CROSSTERMS
5598  /* Assign the constants */
5599  crossterm_ptr->crossterm_type = ptr->index;
5600 #endif
5601  return;
5602 }
char atom8name[11]
Definition: Parameters.C:138
Index crossterm_type
Definition: structures.h:91
char atom5name[11]
Definition: Parameters.C:135
char atom1name[11]
Definition: Parameters.C:131
int32 atom5
Definition: structures.h:87
int32 atom8
Definition: structures.h:90
TupleString< 8 > TupleString8
Definition: TupleString.h:259
struct crossterm_params * next
Definition: Parameters.C:142
int32 atom1
Definition: structures.h:83
int32 atom4
Definition: structures.h:86
int32 atom3
Definition: structures.h:85
char atom7name[11]
Definition: Parameters.C:137
int32 atom2
Definition: structures.h:84
int32 atom7
Definition: structures.h:89
char atom3name[11]
Definition: Parameters.C:133
void NAMD_die(const char *err_msg)
Definition: common.C:147
char atom4name[11]
Definition: Parameters.C:134
char atom2name[11]
Definition: Parameters.C:132
int32 atom6
Definition: structures.h:88
int64_t const index(const TupleString< NumStrings > &findKey) const
Definition: TupleString.h:340
char atom6name[11]
Definition: Parameters.C:136

◆ assign_dihedral_index()

void Parameters::assign_dihedral_index ( const char *  atom1,
const char *  atom2,
const char *  atom3,
const char *  atom4,
Dihedral dihedral_ptr,
int  multiplicity,
int  notFoundIndex 
)

Definition at line 4962 of file Parameters.C.

References dihedral::atom1, dihedral::atom2, dihedral::atom3, dihedral::atom4, dihedral_array, dihedral::dihedral_type, endi(), TwoLevelParam< NumStrings, ParamValue >::index(), iout, iWARN(), DihedralValue::multiplicity, NAMD_die(), and paraXplor.

4966 {
4967  int found=0; // Flag 1->found a match
4968  struct dihedral_params *ptr; // Current position in list
4969 #ifndef ACCELERATED_INPUT_DIHEDRALS
4970 
4971  /* Start at the begining of the list */
4972  ptr=dihedralp;
4973 
4974  /* While we haven't found a match and we haven't reached */
4975  /* the end of the list, keep looking */
4976  while (!found && (ptr!=NULL))
4977  {
4978  /* Do a linear search through the linked list of */
4979  /* dihedral parameters. Since the list is arranged */
4980  /* with wildcard paramters at the end of the list, we */
4981  /* can simply do a linear search and be guaranteed that*/
4982  /* we will find exact matches before wildcard matches. */
4983  /* Also, we must check for an exact match, and a match */
4984  /* in reverse, since they are really the same */
4985  /* physically. */
4986  if ( ( ptr->atom1wild || (strcasecmp(ptr->atom1name, atom1)==0) ) &&
4987  ( ptr->atom2wild || (strcasecmp(ptr->atom2name, atom2)==0) ) &&
4988  ( ptr->atom3wild || (strcasecmp(ptr->atom3name, atom3)==0) ) &&
4989  ( ptr->atom4wild || (strcasecmp(ptr->atom4name, atom4)==0) ) )
4990  {
4991  /* Found an exact match */
4992  found=1;
4993  }
4994  else if ( ( ptr->atom4wild || (strcasecmp(ptr->atom4name, atom1)==0) ) &&
4995  ( ptr->atom3wild || (strcasecmp(ptr->atom3name, atom2)==0) ) &&
4996  ( ptr->atom2wild || (strcasecmp(ptr->atom2name, atom3)==0) ) &&
4997  ( ptr->atom1wild || (strcasecmp(ptr->atom1name, atom4)==0) ) )
4998  {
4999  /* Found a reverse match */
5000  found=1;
5001  }
5002  else
5003  {
5004  /* Didn't find a match, go to the next node */
5005  ptr=ptr->next;
5006  }
5007  }
5008 #else
5009  int cmp= strcasecmp(atom1, atom4);
5010  bool reverse=false;
5011  if(cmp==0)
5012  {
5013  if(strcasecmp(atom2, atom3)>0)
5014  {
5015  reverse=true;
5016  }
5017  }
5018  else if (cmp > 0)
5019  reverse=true;
5020 
5021  TupleString4 searchFor= (reverse) ?
5022  TupleString4(atom4, atom3, atom2, atom1) :
5023  TupleString4(atom1, atom2, atom3, atom4);
5024  int64_t result = dihedralmap->index(searchFor);
5025  if(result >= 0)
5026  {
5027  found=true;
5028  dihedral_ptr->dihedral_type = result;
5029  }
5030  if (!found) // check for wild cards forward and reversed
5031  {
5032  TupleString4 searchForW[11];
5033  TupleString4 searchForWR[11];
5034  searchForWR[0] = TupleString4("X", atom3, atom2, "X");
5035  searchForWR[1] = TupleString4("X", atom2, atom3, "X");
5036  searchForWR[2] = TupleString4(atom4, atom3, atom2, "X");
5037  searchForWR[3] = TupleString4(atom4, atom3, "X", atom1);
5038  searchForWR[4] = TupleString4(atom4, "X", atom2, atom1);
5039  searchForWR[5] = TupleString4("X", atom3, atom2, atom1);
5040  searchForWR[6] = TupleString4(atom4, "X", "X", atom1);
5041  searchForWR[7] = TupleString4(atom4, atom3, "X", "X");
5042  searchForWR[8] = TupleString4("X","X", atom2, atom1);
5043  searchForWR[9] = TupleString4(atom4, "X", "X", "X");
5044  searchForWR[10] = TupleString4("X","X", "X", atom1);
5045  searchForW[0] = TupleString4("X", atom2, atom3, "X");
5046  searchForW[1] = TupleString4("X", atom3, atom2, "X");
5047  searchForW[2] = TupleString4("X", atom2, atom3, atom4);
5048  searchForW[3] = TupleString4(atom1, "X", atom3, atom4);
5049  searchForW[4] = TupleString4(atom1, atom2, "X", atom4);
5050  searchForW[5] = TupleString4(atom1, atom2, atom3, "X");
5051  searchForW[6] = TupleString4(atom1, "X", "X", atom4);
5052  searchForW[7] = TupleString4("X", "X", atom3, atom4);
5053  searchForW[8] = TupleString4(atom1, atom2, "X", "X");
5054  searchForW[9] = TupleString4("X", "X", "X", atom4);
5055  searchForW[10] = TupleString4(atom1, "X", "X", "X");
5056 
5057  for(int i=0; i<11; ++i)
5058  {
5059  result = dihedralmap->index(searchForW[i]);
5060  if(result >= 0)
5061  {
5062  found=true;
5063  dihedral_ptr->dihedral_type = result;
5064  break;
5065  }
5066  }
5067  if(!found)
5068  {
5069  for(int i=0; i<11; ++i)
5070  {
5071  result = dihedralmap->index(searchForWR[i]);
5072  if(result >= 0)
5073  {
5074  found=true;
5075  dihedral_ptr->dihedral_type = result;
5076  break;
5077  }
5078  }
5079  }
5080  }
5081 #endif
5082  /* Make sure we found a match */
5083  if (!found)
5084  {
5085  char err_msg[512];
5086 #ifdef ACCELERATED_INPUT_DIHEDRALS
5087  if(reverse)
5088  {
5089  snprintf(err_msg, sizeof(err_msg),
5090  "UNABLE TO FIND DIHEDRAL PARAMETERS FOR %s %s %s %s "
5091  "(ATOMS %i %i %i %i)",
5092  atom4, atom3, atom2, atom1,
5093  dihedral_ptr->atom4+1, dihedral_ptr->atom3+1,
5094  dihedral_ptr->atom2+1, dihedral_ptr->atom1+1);
5095  }
5096  else
5097 #endif
5098  { snprintf(err_msg, sizeof(err_msg),
5099  "UNABLE TO FIND DIHEDRAL PARAMETERS FOR %s %s %s %s "
5100  "(ATOMS %i %i %i %i)",
5101  atom1, atom2, atom3, atom4,
5102  dihedral_ptr->atom1+1, dihedral_ptr->atom2+1,
5103  dihedral_ptr->atom3+1, dihedral_ptr->atom4+1);
5104  }
5105  if ( notFoundIndex ) {
5106  dihedral_ptr->dihedral_type = notFoundIndex;
5107  iout << iWARN << err_msg << "\n" << endi;
5108  return;
5109  } else NAMD_die(err_msg);
5110  }
5111 
5112 #ifndef ACCELERATED_INPUT_DIHEDRALS
5113  int index = ptr->index;
5114 #else
5115  int index = result;
5116 #endif
5117  if (paramType == paraXplor) {
5118  // Check to make sure the number of multiples specified in the psf
5119  // file doesn't exceed the number of parameters in the parameter
5120  // files
5121  if (multiplicity > maxDihedralMults[index])
5122  {
5123  char err_msg[512];
5124 
5125  snprintf(err_msg, sizeof(err_msg),
5126  "Multiplicity of Paramters for dihedral bond %s %s %s %s "
5127  "of %d exceeded",
5128  atom1, atom2, atom3, atom4, maxDihedralMults[index]);
5129  NAMD_die(err_msg);
5130  }
5131 
5132  // If the multiplicity from the current bond is larger than that
5133  // seen in the past, increase the multiplicity for this bond
5134  if (multiplicity > dihedral_array[index].multiplicity)
5135  {
5136  dihedral_array[index].multiplicity = multiplicity;
5137  }
5138  }
5139 
5140  dihedral_ptr->dihedral_type = index;
5141 
5142  return;
5143 }
int32 atom3
Definition: structures.h:67
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
std::ostream & iWARN(std::ostream &s)
Definition: InfoStream.C:82
DihedralValue * dihedral_array
Definition: Parameters.h:314
#define iout
Definition: InfoStream.h:51
int32 atom4
Definition: structures.h:68
Index dihedral_type
Definition: structures.h:69
void NAMD_die(const char *err_msg)
Definition: common.C:147
int32 atom2
Definition: structures.h:66
#define paraXplor
Definition: Parameters.h:96
int64_t const index(const TupleString< NumStrings > &findKey) const
Definition: TupleString.h:340
TupleString< 4 > TupleString4
Definition: TupleString.h:258
int32 atom1
Definition: structures.h:65

◆ assign_improper_index()

void Parameters::assign_improper_index ( const char *  atom1,
const char *  atom2,
const char *  atom3,
const char *  atom4,
Improper improper_ptr,
int  multiplicity 
)

Definition at line 5167 of file Parameters.C.

References improper::atom1, improper_params::atom1name, improper::atom2, improper_params::atom2name, improper::atom3, improper_params::atom3name, improper::atom4, improper_params::atom4name, improper_array, improper::improper_type, improper_params::index, TwoLevelParam< NumStrings, ParamValue >::index(), improper_params::multiplicity, ImproperValue::multiplicity, NAMD_die(), improper_params::next, and paraXplor.

5171 {
5172  int found=0; // Flag 1->found a match
5173 #ifndef ACCELERATED_INPUT_IMPROPERS
5174  struct improper_params *ptr; // Current position in list
5175 
5176 
5177  /* Start at the head of the list */
5178  ptr=improperp;
5179 
5180  /* While we haven't fuond a match and haven't reached the end */
5181  /* of the list, keep looking */
5182  while (!found && (ptr!=NULL))
5183  {
5184  /* Do a linear search through the linked list of */
5185  /* improper parameters. Since the list is arranged */
5186  /* with wildcard paramters at the end of the list, we */
5187  /* can simply do a linear search and be guaranteed that*/
5188  /* we will find exact matches before wildcard matches. */
5189  /* Also, we must check for an exact match, and a match */
5190  /* in reverse, since they are really the same */
5191  /* physically. */
5192  if ( ( (strcasecmp(ptr->atom1name, atom1)==0) ||
5193  (strcasecmp(ptr->atom1name, "X")==0) ) &&
5194  ( (strcasecmp(ptr->atom2name, atom2)==0) ||
5195  (strcasecmp(ptr->atom2name, "X")==0) ) &&
5196  ( (strcasecmp(ptr->atom3name, atom3)==0) ||
5197  (strcasecmp(ptr->atom3name, "X")==0) ) &&
5198  ( (strcasecmp(ptr->atom4name, atom4)==0) ||
5199  (strcasecmp(ptr->atom4name, "X")==0) ) )
5200  {
5201  /* Found an exact match */
5202  found=1;
5203  }
5204  else if ( ( (strcasecmp(ptr->atom4name, atom1)==0) ||
5205  (strcasecmp(ptr->atom4name, "X")==0) ) &&
5206  ( (strcasecmp(ptr->atom3name, atom2)==0) ||
5207  (strcasecmp(ptr->atom3name, "X")==0) ) &&
5208  ( (strcasecmp(ptr->atom2name, atom3)==0) ||
5209  (strcasecmp(ptr->atom2name, "X")==0) ) &&
5210  ( (strcasecmp(ptr->atom1name, atom4)==0) ||
5211  (strcasecmp(ptr->atom1name, "X")==0) ) )
5212  {
5213  /* Found a reverse match */
5214  found=1;
5215  }
5216  else
5217  {
5218  /* Didn't find a match, go to the next node */
5219  ptr=ptr->next;
5220  }
5221  }
5222 #else
5223  int cmp= strcasecmp(atom1, atom4);
5224  bool reverse=false;
5225  if(cmp==0)
5226  {
5227  if(strcasecmp(atom2, atom3)>0)
5228  {
5229  reverse=true;
5230  }
5231  }
5232  else if (cmp > 0)
5233  reverse=true;
5234  TupleString4 searchFor= (reverse) ?
5235  TupleString4(atom4,atom3, atom2, atom1) :
5236  TupleString4(atom1,atom2, atom3, atom4);
5237  int64_t result = impropermap->index(searchFor);
5238  if(result >= 0)
5239  {
5240  found=true;
5241  improper_ptr->improper_type = result;
5242  }
5243  if (!found) // check for wild cards both forward and reversed
5244  {
5245  TupleString4 searchForWR[13];
5246  TupleString4 searchForW[13];
5247  searchForWR[0] = TupleString4("X", atom3, atom2, "X");
5248  searchForWR[1] = TupleString4("X", atom2, atom3, "X");
5249  searchForWR[2] = TupleString4(atom4, atom3, atom2, "X");
5250  searchForWR[3] = TupleString4(atom4, atom3, "X", atom1);
5251  searchForWR[4] = TupleString4(atom4, "X", atom2, atom1);
5252  searchForWR[5] = TupleString4("X", atom3, atom2, atom1);
5253  searchForWR[6] = TupleString4(atom4, "X", "X", atom1);
5254  searchForWR[7] = TupleString4(atom4, atom3, "X", "X");
5255  searchForWR[8] = TupleString4("X","X", atom2, atom1);
5256  searchForWR[9] = TupleString4(atom4, "X", "X", "X");
5257  searchForWR[10] = TupleString4("X","X", "X", atom1);
5258  searchForWR[11] = TupleString4("X",atom3, "X", atom1);
5259  searchForWR[12] = TupleString4(atom4,"X", atom2, "X");
5260  searchForW[0] = TupleString4("X", atom2, atom3, "X");
5261  searchForW[1] = TupleString4("X", atom3, atom2, "X");
5262  searchForW[2] = TupleString4("X", atom2, atom3, atom4);
5263  searchForW[3] = TupleString4(atom1, "X", atom3, atom4);
5264  searchForW[4] = TupleString4(atom1, atom2, "X", atom4);
5265  searchForW[5] = TupleString4(atom1, atom2, atom3, "X");
5266  searchForW[6] = TupleString4(atom1, "X", "X", atom4);
5267  searchForW[7] = TupleString4("X", "X", atom3, atom4);
5268  searchForW[8] = TupleString4(atom1, atom2, "X", "X");
5269  searchForW[9] = TupleString4("X", "X", "X", atom4);
5270  searchForW[10] = TupleString4(atom1, "X", "X", "X");
5271  searchForW[11] = TupleString4("X", atom2, "X", atom4);
5272  searchForW[12] = TupleString4(atom1, "X",atom3, "X");
5273  for(int i=0; i<13; ++i)
5274  {
5275  result = impropermap->index(searchForW[i]);
5276  if(result >= 0)
5277  {
5278  found=true;
5279  improper_ptr->improper_type = result;
5280  break;
5281  }
5282  }
5283  if(!found)
5284  for(int i=0; i<13; ++i)
5285  {
5286  result = impropermap->index(searchForWR[i]);
5287  if(result >= 0)
5288  {
5289  found=true;
5290  improper_ptr->improper_type = result;
5291  break;
5292  }
5293  }
5294  }
5295 #endif
5296  /* Make sure we found a match */
5297  if (!found)
5298  {
5299  char err_msg[512];
5300 
5301  snprintf(err_msg, sizeof(err_msg),
5302  "UNABLE TO FIND IMPROPER PARAMETERS FOR %s %s %s %s "
5303  "(ATOMS %i %i %i %i)",
5304  atom1, atom2, atom3, atom4,
5305  improper_ptr->atom1+1, improper_ptr->atom2+1,
5306  improper_ptr->atom3+1, improper_ptr->atom4+1);
5307 
5308  NAMD_die(err_msg);
5309  }
5310 #ifndef ACCELERATED_INPUT_IMPROPERS
5311  int index = ptr->index;
5312 #else
5313  int index = result;
5314 #endif
5315 
5316  if (paramType == paraXplor) {
5317  // Check to make sure the number of multiples specified in the psf
5318  // file doesn't exceed the number of parameters in the parameter
5319  // files
5320  if (multiplicity > maxImproperMults[index])
5321  {
5322  char err_msg[512];
5323 
5324  snprintf(err_msg, sizeof(err_msg),
5325  "Multiplicity of Paramters for improper bond %s %s %s %s "
5326  "of %d exceeded",
5327  atom1, atom2, atom3, atom4, maxImproperMults[index]);
5328  NAMD_die(err_msg);
5329  }
5330 
5331  // If the multiplicity from the current bond is larger than that
5332  // seen in the past, increase the multiplicity for this bond
5334  {
5336  }
5337  }
5338 
5339  /* Assign the constants */
5340  improper_ptr->improper_type = index;
5341 
5342  return;
5343 }
struct improper_params * next
Definition: Parameters.C:120
int32 atom4
Definition: structures.h:77
Index improper_type
Definition: structures.h:78
char atom2name[11]
Definition: Parameters.C:114
char atom3name[11]
Definition: Parameters.C:115
ImproperValue * improper_array
Definition: Parameters.h:315
void NAMD_die(const char *err_msg)
Definition: common.C:147
char atom4name[11]
Definition: Parameters.C:116
int32 atom1
Definition: structures.h:74
#define paraXplor
Definition: Parameters.h:96
int32 atom2
Definition: structures.h:75
int64_t const index(const TupleString< NumStrings > &findKey) const
Definition: TupleString.h:340
TupleString< 4 > TupleString4
Definition: TupleString.h:258
char atom1name[11]
Definition: Parameters.C:113
int32 atom3
Definition: structures.h:76

◆ assign_vdw_index()

void Parameters::assign_vdw_index ( const char *  atomtype,
Atom atom_ptr 
)

Definition at line 4399 of file Parameters.C.

References ResizeArray< Elem >::add(), vdw_params::atomname, endi(), vdw_params::index, iout, iWARN(), vdw_params::left, NAMD_die(), vdw_params::right, ResizeArray< Elem >::size(), and atom_constants::vdw_type.

Referenced by Molecule::prepare_qm().

4401 {
4402  int found=0; // Flag 1->found match
4403 #ifndef ACCELERATED_INPUT_VDW
4404  struct vdw_params *ptr; // Current position in trees
4405 
4406  int comp_code; // return code from strcasecmp
4407 
4408  /* Check to make sure the files have all been read */
4409  if (!AllFilesRead)
4410  {
4411  NAMD_die("Tried to assign vdw index before all parameter files were read");
4412  }
4413 
4414  /* Start at the top */
4415  ptr=vdwp;
4416 
4417  /* While we haven't found a match, and we haven't reached */
4418  /* the bottom of the tree, compare the atom passed in with */
4419  /* the current value and decide if we have a match, or if not, */
4420  /* which way to go */
4421  while (!found && (ptr!=NULL))
4422  {
4423  comp_code = strcasecmp(atomtype, ptr->atomname);
4424 
4425  if (comp_code == 0)
4426  {
4427  /* Found a match! */
4428  atom_ptr->vdw_type=ptr->index;
4429  found=1;
4430  }
4431  else if (comp_code < 0)
4432  {
4433  /* Go to the left */
4434  ptr=ptr->left;
4435  }
4436  else
4437  {
4438  /* Go to the right */
4439  ptr=ptr->right;
4440  }
4441  }
4442 #else
4443  TupleString1 searchFor(atomtype);
4444  int64_t result = vdwmap->index(searchFor);
4445  if(result>=0)
4446  {
4447  found=1;
4448  atom_ptr->vdw_type = result;
4449  }
4450 #endif
4451 
4452  //****** BEGIN CHARMM/XPLOR type changes
4453  if (!found)
4454  {
4455 #ifndef ACCELERATED_INPUT_VDW
4456  // since CHARMM allows wildcards "*" in vdw typenames
4457  // we have to look again if necessary, this way, if
4458  // we already had an exact match, this is never executed
4459  size_t windx; // wildcard index
4460 
4461 
4462  /* Start again at the top */
4463  ptr=vdwp;
4464 
4465  while (!found && (ptr!=NULL))
4466  {
4467 
4468  // get index of wildcard wildcard, get index
4469  windx= strcspn(ptr->atomname,"*");
4470  if (windx == strlen(ptr->atomname))
4471  {
4472  // there is no wildcard here
4473  comp_code = strcasecmp(atomtype, ptr->atomname);
4474  }
4475  else
4476  {
4477  comp_code = strncasecmp(atomtype, ptr->atomname, windx);
4478  }
4479 
4480  if (comp_code == 0)
4481  {
4482  /* Found a match! */
4483  atom_ptr->vdw_type=ptr->index;
4484  found=1;
4485  char errbuf[100];
4486  snprintf(errbuf, sizeof(errbuf),
4487  "VDW TYPE NAME %s MATCHES PARAMETER TYPE NAME %s",
4488  atomtype, ptr->atomname);
4489  int i;
4490  for(i=0; i<error_msgs.size(); i++) {
4491  if ( strcmp(errbuf,error_msgs[i]) == 0 ) break;
4492  }
4493  if ( i == error_msgs.size() ) {
4494  char *newbuf = new char[strlen(errbuf)+1];
4495  strcpy(newbuf,errbuf);
4496  error_msgs.add(newbuf);
4497  iout << iWARN << newbuf << "\n" << endi;
4498  }
4499  }
4500  else if (comp_code < 0)
4501  {
4502  /* Go to the left */
4503  ptr=ptr->left;
4504  }
4505  else
4506  {
4507  /* Go to the right */
4508  ptr=ptr->right;
4509  }
4510 
4511  }
4512 #else
4513  TupleString1 searchFor("*");
4514  int64_t result = vdwmap->index(searchFor);
4515  if(result>=0)
4516  {
4517  found=1;
4518  atom_ptr->vdw_type = result;
4519  }
4520 #endif
4521  }
4522  //****** END CHARMM/XPLOR type changes
4523 
4524  /* Make sure we found it */
4525  if (!found)
4526  {
4527  char err_msg[512];
4528 
4529  snprintf(err_msg, sizeof(err_msg),
4530  "DIDN'T FIND vdW PARAMETER FOR ATOM TYPE %s", atomtype);
4531  NAMD_die(err_msg);
4532  }
4533 
4534  return;
4535 }
int size(void) const
Definition: ResizeArray.h:131
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
std::ostream & iWARN(std::ostream &s)
Definition: InfoStream.C:82
#define iout
Definition: InfoStream.h:51
int add(const Elem &elem)
Definition: ResizeArray.h:101
char atomname[11]
Definition: Parameters.C:150
struct vdw_params * left
Definition: Parameters.C:156
void NAMD_die(const char *err_msg)
Definition: common.C:147
Index vdw_type
Definition: structures.h:39
Index index
Definition: Parameters.C:155
struct vdw_params * right
Definition: Parameters.C:157

◆ atom_type_name()

char* Parameters::atom_type_name ( Index  a)
inline

Definition at line 465 of file Parameters.h.

References MAX_ATOMTYPE_CHARS.

465  {
466  return (atomTypeNames + (a * (MAX_ATOMTYPE_CHARS + 1)));
467  }
#define MAX_ATOMTYPE_CHARS
Definition: Parameters.h:91

◆ done_reading_files()

void Parameters::done_reading_files ( Bool  addDrudeBond)

Definition at line 3813 of file Parameters.C.

References angle_array, bond_array, crossterm_array, dihedral_array, FALSE, gromacsPair_array, improper_array, MAX_ATOMTYPE_CHARS, NAMD_die(), nbthole_array, AngleValue::normal, NumAngleParams, NumBondParams, NumCrosstermParams, NumDihedralParams, NumGromacsPairParams, NumImproperParams, NumNbtholePairParams, NumVdwParams, NumVdwParamsAssigned, TRUE, and vdw_array.

Referenced by Parameters().

3815 {
3816  AllFilesRead = TRUE;
3817 
3818  if (addDrudeBond) {
3819  // default definition for Drude bonds if none given
3820  NumBondParams++;
3821  add_bond_param("X DRUD 500.0 0.0\n", FALSE);
3822  }
3823  // Allocate space for all of the arrays
3824  if (NumBondParams)
3825  {
3827 
3828  if (bond_array == NULL)
3829  {
3830  NAMD_die("memory allocation of bond_array failed!");
3831  }
3832  memset(bond_array, 0, NumBondParams*sizeof(BondValue));
3833  }
3834 
3835  if (NumAngleParams)
3836  {
3838 
3839  if (angle_array == NULL)
3840  {
3841  NAMD_die("memory allocation of angle_array failed!");
3842  }
3843  memset(angle_array, 0, NumAngleParams*sizeof(AngleValue));
3844  for ( Index i=0; i<NumAngleParams; ++i ) {
3845  angle_array[i].normal = 1;
3846  }
3847  }
3848 
3849  if (NumDihedralParams)
3850  {
3852 
3853  if (dihedral_array == NULL)
3854  {
3855  NAMD_die("memory allocation of dihedral_array failed!");
3856  }
3857  memset(dihedral_array, 0, NumDihedralParams*sizeof(DihedralValue));
3858  }
3859 
3860  if (NumImproperParams)
3861  {
3863 
3864  if (improper_array == NULL)
3865  {
3866  NAMD_die("memory allocation of improper_array failed!");
3867  }
3868  memset(improper_array, 0, NumImproperParams*sizeof(ImproperValue));
3869  }
3870 
3871  if (NumCrosstermParams)
3872  {
3875  }
3876 
3877  // JLai
3879  {
3882  }
3883  // End of JLai
3884 
3885  if (NumVdwParams)
3886  {
3887  atomTypeNames = new char[NumVdwParams*(MAX_ATOMTYPE_CHARS+1)];
3889 
3890  if (vdw_array == NULL)
3891  {
3892  NAMD_die("memory allocation of vdw_array failed!");
3893  }
3894  }
3896  {
3898 
3899  if(nbthole_array == NULL)
3900  {
3901  NAMD_die("memory allocation of nbthole_array failed!");
3902  }
3903  }
3904  // Assign indexes to each of the parameters and populate the
3905  // arrays using the binary trees and linked lists that we have
3906  // already read in
3907 
3908  // Note that if parameters have been overwritten (matching
3909  // atom patterns but different parameter values) the tree
3910  // contains fewer elements than Num...Params would suggest.
3911  // The arrays are initialized above because the end values
3912  // may not be occupied. Modifying the Num...Params values
3913  // would break backwards compatibility of memopt extraBonds.
3914 
3915  index_bonds(bondp, 0);
3916  index_angles(anglep, 0);
3917  NumVdwParamsAssigned = index_vdw(vdwp, 0);
3918  index_dihedrals();
3919  index_impropers();
3920  index_crossterms();
3921  convert_nbthole_pairs();
3922  // Convert the vdw pairs
3923  convert_vdw_pairs();
3924 
3925  convert_table_pairs();
3926 }
GromacsPairValue * gromacsPair_array
Definition: Parameters.h:318
int NumBondParams
Definition: Parameters.h:330
int NumVdwParams
Definition: Parameters.h:339
#define FALSE
Definition: common.h:127
DihedralValue * dihedral_array
Definition: Parameters.h:314
int NumAngleParams
Definition: Parameters.h:331
CrosstermValue * crossterm_array
Definition: Parameters.h:316
int NumDihedralParams
Definition: Parameters.h:333
AngleValue * angle_array
Definition: Parameters.h:313
int Index
Definition: structures.h:26
int NumNbtholePairParams
Definition: Parameters.h:343
int NumImproperParams
Definition: Parameters.h:334
int NumCrosstermParams
Definition: Parameters.h:335
ImproperValue * improper_array
Definition: Parameters.h:315
void NAMD_die(const char *err_msg)
Definition: common.C:147
int NumVdwParamsAssigned
Definition: Parameters.h:341
NbtholePairValue * nbthole_array
Definition: Parameters.h:321
VdwValue * vdw_array
Definition: Parameters.h:320
BondValue * bond_array
Definition: Parameters.h:312
int NumGromacsPairParams
Definition: Parameters.h:337
#define TRUE
Definition: common.h:128
#define MAX_ATOMTYPE_CHARS
Definition: Parameters.h:91

◆ done_reading_structure()

void Parameters::done_reading_structure ( )

Definition at line 6511 of file Parameters.C.

6513 {
6514  if (bondp != NULL)
6515  free_bond_tree(bondp);
6516 
6517  if (anglep != NULL)
6518  free_angle_tree(anglep);
6519 
6520  if (dihedralp != NULL)
6521  free_dihedral_list(dihedralp);
6522 
6523  if (improperp != NULL)
6524  free_improper_list(improperp);
6525 
6526  if (crosstermp != NULL)
6527  free_crossterm_list(crosstermp);
6528 
6529  if (vdwp != NULL)
6530  free_vdw_tree(vdwp);
6531 
6532  // Free the arrays used to track multiplicity for dihedrals
6533  // and impropers
6534  if (maxDihedralMults != NULL)
6535  delete [] maxDihedralMults;
6536 
6537  if (maxImproperMults != NULL)
6538  delete [] maxImproperMults;
6539 
6540  bondp=NULL;
6541  anglep=NULL;
6542  dihedralp=NULL;
6543  improperp=NULL;
6544  crosstermp=NULL;
6545  vdwp=NULL;
6546  maxImproperMults=NULL;
6547  maxDihedralMults=NULL;
6548 }

◆ get_angle_params()

void Parameters::get_angle_params ( Real k,
Real theta0,
Real k_ub,
Real r_ub,
Index  index 
)
inline

Definition at line 525 of file Parameters.h.

References angle_array, vdw_params::index, AngleValue::k, AngleValue::k_ub, AngleValue::r_ub, and AngleValue::theta0.

527  {
528  *k = angle_array[index].k;
529  *theta0 = angle_array[index].theta0;
530  *k_ub = angle_array[index].k_ub;
531  *r_ub = angle_array[index].r_ub;
532  }
AngleValue * angle_array
Definition: Parameters.h:313
Index index
Definition: Parameters.C:155
Real theta0
Definition: Parameters.h:112

◆ get_bond_params()

void Parameters::get_bond_params ( Real k,
Real x0,
Index  index 
)
inline

Definition at line 519 of file Parameters.h.

References bond_array, vdw_params::index, BondValue::k, and BondValue::x0.

Referenced by Molecule::print_bonds().

520  {
521  *k = bond_array[index].k;
522  *x0 = bond_array[index].x0;
523  }
Index index
Definition: Parameters.C:155
BondValue * bond_array
Definition: Parameters.h:312

◆ get_dihedral_multiplicity()

int Parameters::get_dihedral_multiplicity ( Index  index)
inline

Definition at line 539 of file Parameters.h.

References dihedral_array, and vdw_params::index.

540  {
541  return(dihedral_array[index].multiplicity);
542  }
DihedralValue * dihedral_array
Definition: Parameters.h:314
Index index
Definition: Parameters.C:155

◆ get_dihedral_params()

void Parameters::get_dihedral_params ( Real k,
int *  n,
Real delta,
Index  index,
int  mult 
)
inline

Definition at line 557 of file Parameters.h.

References four_body_consts::delta, dihedral_array, vdw_params::index, four_body_consts::k, MAX_MULTIPLICITY, four_body_consts::n, NAMD_die(), and DihedralValue::values.

559  {
560  if ( (mult<0) || (mult>MAX_MULTIPLICITY) )
561  {
562  NAMD_die("Bad mult index in Parameters::get_dihedral_params");
563  }
564 
565  *k = dihedral_array[index].values[mult].k;
566  *n = dihedral_array[index].values[mult].n;
567  *delta = dihedral_array[index].values[mult].delta;
568  }
DihedralValue * dihedral_array
Definition: Parameters.h:314
FourBodyConsts values[MAX_MULTIPLICITY]
Definition: Parameters.h:128
#define MAX_MULTIPLICITY
Definition: Parameters.h:88
void NAMD_die(const char *err_msg)
Definition: common.C:147
Index index
Definition: Parameters.C:155

◆ get_improper_multiplicity()

int Parameters::get_improper_multiplicity ( Index  index)
inline

Definition at line 534 of file Parameters.h.

References improper_array, and vdw_params::index.

535  {
536  return(improper_array[index].multiplicity);
537  }
ImproperValue * improper_array
Definition: Parameters.h:315
Index index
Definition: Parameters.C:155

◆ get_improper_params()

void Parameters::get_improper_params ( Real k,
int *  n,
Real delta,
Index  index,
int  mult 
)
inline

Definition at line 544 of file Parameters.h.

References four_body_consts::delta, improper_array, vdw_params::index, four_body_consts::k, MAX_MULTIPLICITY, four_body_consts::n, NAMD_die(), and ImproperValue::values.

546  {
547  if ( (mult<0) || (mult>MAX_MULTIPLICITY) )
548  {
549  NAMD_die("Bad mult index in Parameters::get_improper_params");
550  }
551 
552  *k = improper_array[index].values[mult].k;
553  *n = improper_array[index].values[mult].n;
554  *delta = improper_array[index].values[mult].delta;
555  }
#define MAX_MULTIPLICITY
Definition: Parameters.h:88
ImproperValue * improper_array
Definition: Parameters.h:315
void NAMD_die(const char *err_msg)
Definition: common.C:147
FourBodyConsts values[MAX_MULTIPLICITY]
Definition: Parameters.h:134
Index index
Definition: Parameters.C:155

◆ get_int_table_type()

int Parameters::get_int_table_type ( char *  tabletype)

Definition at line 9371 of file Parameters.C.

References table_types, and tablenumtypes.

9371  {
9372  for (int i=0; i<tablenumtypes; i++) {
9373  if (!strncmp(tabletype, table_types[i], 5)) {
9374  return i;
9375  }
9376  }
9377 
9378  return -1;
9379 }
static char ** table_types
Definition: Parameters.C:39
int tablenumtypes
Definition: Parameters.h:329

◆ get_num_vdw_params()

int Parameters::get_num_vdw_params ( void  )
inline

◆ get_table_pair_params()

int Parameters::get_table_pair_params ( Index  ind1,
Index  ind2,
int *  K 
)

Definition at line 4556 of file Parameters.C.

References FALSE, indexed_table_pair::ind1, indexed_table_pair::ind2, indexed_table_pair::K, tab_pair_tree, and TRUE.

Referenced by ComputeLjPmeSerialMgr::getLJparameters().

4556  {
4557  IndexedTablePair *ptr;
4558  Index temp;
4559  int found=FALSE;
4560 
4561  ptr=tab_pair_tree;
4562  //
4563  // We need the smaller type in ind1, so if it isn't already that
4564  // way, switch them */
4565  if (ind1 > ind2)
4566  {
4567  temp = ind1;
4568  ind1 = ind2;
4569  ind2 = temp;
4570  }
4571 #ifndef ACCELERATED_INPUT_VDW
4572  /* While we haven't found a match and we're not at the end */
4573  /* of the tree, compare the bond passed in with the tree */
4574  while (!found && (ptr!=NULL))
4575  {
4576 // printf("Comparing %i with %i and %i with %i\n", ind1, ptr->ind1, ind2, ptr->ind2);
4577  if ( (ind1 == ptr->ind1) && (ind2 == ptr->ind2) )
4578  {
4579  found = TRUE;
4580  }
4581  else if ( (ind1 < ptr->ind1) ||
4582  ( (ind1==ptr->ind1) && (ind2 < ptr->ind2) ) )
4583  {
4584  /* Go left */
4585  ptr=ptr->left;
4586  }
4587  else
4588  {
4589  /* Go right */
4590  ptr=ptr->right;
4591  }
4592  }
4593 
4594  /* If we found a match, assign the values */
4595  if (found)
4596  {
4597  *K = ptr->K;
4598  return(TRUE);
4599  }
4600  else
4601  {
4602  return(FALSE);
4603  }
4604 #else
4605  uint64_t k1= ind1;
4606  uint64_t k2= ind2;
4607  uint64_t key= ((k1 <<32) | k2);
4608  auto ret = tablepairmap.find(key);
4609  if(ret!=tablepairmap.end())
4610  {
4611  *K = ret->second.K;
4612  return(TRUE);
4613  }
4614  else
4615  {
4616  return(FALSE);
4617  }
4618 #endif
4619 }
#define FALSE
Definition: common.h:127
int Index
Definition: structures.h:26
IndexedTablePair * tab_pair_tree
Definition: Parameters.h:328
#define TRUE
Definition: common.h:128

◆ get_vdw_pair_params()

int Parameters::get_vdw_pair_params ( Index  ind1,
Index  ind2,
Real A,
Real B,
Real A14,
Real B14 
)

Definition at line 4646 of file Parameters.C.

References indexed_vdw_pair::A, indexed_vdw_pair::A14, indexed_vdw_pair::B, indexed_vdw_pair::B14, FALSE, indexed_vdw_pair::ind1, indexed_vdw_pair::ind2, indexed_vdw_pair::left, indexed_vdw_pair::right, TRUE, and vdw_pair_tree.

Referenced by get_vdw_params(), ComputeLjPmeSerialMgr::getLJparameters(), and ComputeNonbondedUtil::select().

4649 {
4650  IndexedVdwPair *ptr; // Current location in tree
4651  Index temp; // Temporary value for swithcing
4652  // values
4653  int found=FALSE; // Flag 1-> found a match
4654 
4655  ptr=vdw_pair_tree;
4656 
4657  // We need the smaller type in ind1, so if it isn't already that
4658  // way, switch them */
4659  if (ind1 > ind2)
4660  {
4661  temp = ind1;
4662  ind1 = ind2;
4663  ind2 = temp;
4664  }
4665 #ifndef ACCELERATED_INPUT_VDW
4666  /* While we haven't found a match and we're not at the end */
4667  /* of the tree, compare the bond passed in with the tree */
4668  while (!found && (ptr!=NULL))
4669  {
4670  if ( (ind1 == ptr->ind1) && (ind2 == ptr->ind2) )
4671  {
4672  found = TRUE;
4673  }
4674  else if ( (ind1 < ptr->ind1) ||
4675  ( (ind1==ptr->ind1) && (ind2 < ptr->ind2) ) )
4676  {
4677  /* Go left */
4678  ptr=ptr->left;
4679  }
4680  else
4681  {
4682  /* Go right */
4683  ptr=ptr->right;
4684  }
4685  }
4686 
4687  /* If we found a match, assign the values */
4688  if (found)
4689  {
4690  *A = ptr->A;
4691  *B = ptr->B;
4692  *A14 = ptr->A14;
4693  *B14 = ptr->B14;
4694  return(TRUE);
4695  }
4696  else
4697  {
4698  return(FALSE);
4699  }
4700 #else
4701  uint64_t k1= ind1;
4702  uint64_t k2= ind2;
4703  uint64_t key= ((k1 <<32) | k2);
4704  auto ret = vdwpairmap.find(key);
4705  if(ret!=vdwpairmap.end())
4706  {
4707  *A = ret->second.A;
4708  *B = ret->second.B;
4709  *A14 = ret->second.A14;
4710  *B14 = ret->second.B14;
4711  return(TRUE);
4712  }
4713  else
4714  {
4715  return(FALSE);
4716  }
4717 #endif
4718 }
struct indexed_vdw_pair * right
Definition: Parameters.h:191
#define FALSE
Definition: common.h:127
IndexedVdwPair * vdw_pair_tree
Definition: Parameters.h:326
int Index
Definition: structures.h:26
struct indexed_vdw_pair * left
Definition: Parameters.h:192
#define TRUE
Definition: common.h:128

◆ get_vdw_params()

void Parameters::get_vdw_params ( Real sigma,
Real epsilon,
Real sigma14,
Real epsilon14,
Index  index 
)
inline

Definition at line 570 of file Parameters.h.

References cbrt, vdw_params::epsilon, vdw_val::epsilon, vdw_params::epsilon14, vdw_val::epsilon14, get_vdw_pair_params(), vdw_params::index, NAMD_die(), vdw_params::sigma, vdw_val::sigma, vdw_params::sigma14, vdw_val::sigma14, and vdw_array.

Referenced by ComputeLjPmeSerialMgr::getLJparameters(), Molecule::print_atoms(), and ComputeNonbondedUtil::select().

572  {
573  if ( vdw_array ) {
578  } else {
579  // sigma and epsilon from A and B for each vdw type's interaction with itself
580  Real A; Real B; Real A14; Real B14;
581  if (get_vdw_pair_params(index, index, &A, &B, &A14, &B14) ) {
582  if (A && B) {
583  *sigma = sqrt(cbrt(A)) / sqrt(cbrt(B));
584  *epsilon = B*B / (4*A);
585  }
586  else {
587  *sigma = 0; *epsilon = 0;
588  }
589  if (A14 && B14) {
590  *sigma14 = sqrt(cbrt(A14)) / sqrt(cbrt(B14));
591  *epsilon14 = B14*B14 / (4*A14);
592  }
593  else {
594  *sigma14 = 0; *epsilon14 = 0;
595  }
596  }
597  else {NAMD_die ("Function get_vdw_params failed to derive Lennard-Jones sigma and epsilon from A and B values\n");}
598  }
599  }
Real epsilon
Definition: Parameters.h:174
float Real
Definition: common.h:118
Real sigma14
Definition: Parameters.h:175
Real sigma14
Definition: Parameters.C:153
Real epsilon14
Definition: Parameters.C:154
Real sigma
Definition: Parameters.h:173
int get_vdw_pair_params(Index ind1, Index ind2, Real *, Real *, Real *, Real *)
Definition: Parameters.C:4646
void NAMD_die(const char *err_msg)
Definition: common.C:147
VdwValue * vdw_array
Definition: Parameters.h:320
Index index
Definition: Parameters.C:155
Real epsilon14
Definition: Parameters.h:176
Real epsilon
Definition: Parameters.C:152
Real sigma
Definition: Parameters.C:151
#define cbrt(x)
Definition: Parameters.h:51

◆ print_angle_params()

void Parameters::print_angle_params ( )

Definition at line 6344 of file Parameters.C.

References DebugM, and NumAngleParams.

6345 {
6346  DebugM(3,NumAngleParams << " ANGLE PARAMETERS\n"
6347  << "*****************************************\n" );
6348  traverse_angle_params(anglep);
6349 }
#define DebugM(x, y)
Definition: Debug.h:75
int NumAngleParams
Definition: Parameters.h:331

◆ print_bond_params()

void Parameters::print_bond_params ( )

Definition at line 6326 of file Parameters.C.

References DebugM, and NumBondParams.

6327 {
6328  DebugM(3,NumBondParams << " BOND PARAMETERS\n" \
6329  << "*****************************************\n" \
6330  );
6331 
6332  traverse_bond_params(bondp);
6333 }
int NumBondParams
Definition: Parameters.h:330
#define DebugM(x, y)
Definition: Debug.h:75

◆ print_crossterm_params()

void Parameters::print_crossterm_params ( )

Definition at line 6448 of file Parameters.C.

References CrosstermValue::c, crossterm_array, CrosstermData::d00, CrosstermData::d01, CrosstermData::d10, CrosstermData::d11, CrosstermValue::dim, iout, and NumCrosstermParams.

6450 {
6451 
6452  int N = CrosstermValue::dim - 1;
6453  for(int i; i < NumCrosstermParams; ++i)
6454  {
6455  iout << "CROSSTERM "<< i <<" ";
6456  for (int j = 0; j < N; ++j) {
6457  for (int k = 0; k < N; ++k) {
6458  iout << crossterm_array[i].c[j][k].d00 << " "
6459  << crossterm_array[i].c[j][k].d01 << " "
6460  << crossterm_array[i].c[j][k].d10 << " "
6461  << crossterm_array[i].c[j][k].d11 << " ";
6462  }
6463  }
6464  iout << "\n";
6465  }
6466 }
CrosstermData c[dim][dim]
Definition: Parameters.h:145
#define iout
Definition: InfoStream.h:51
CrosstermValue * crossterm_array
Definition: Parameters.h:316
BigReal d11
Definition: Parameters.h:137
BigReal d00
Definition: Parameters.h:137
int NumCrosstermParams
Definition: Parameters.h:335
BigReal d01
Definition: Parameters.h:137
BigReal d10
Definition: Parameters.h:137

◆ print_dihedral_array()

void Parameters::print_dihedral_array ( )

◆ print_dihedral_params()

void Parameters::print_dihedral_params ( )

Definition at line 6360 of file Parameters.C.

References DebugM, and NumDihedralParams.

6361 {
6362  DebugM(3,NumDihedralParams << " DIHEDRAL PARAMETERS\n" \
6363  << "*****************************************\n" );
6364 
6365  traverse_dihedral_params(dihedralp);
6366 }
#define DebugM(x, y)
Definition: Debug.h:75
int NumDihedralParams
Definition: Parameters.h:333

◆ print_improper_params()

void Parameters::print_improper_params ( )

Definition at line 6377 of file Parameters.C.

References DebugM, and NumImproperParams.

6378 {
6379  DebugM(3,NumImproperParams << " IMPROPER PARAMETERS\n" \
6380  << "*****************************************\n" );
6381 
6382  traverse_improper_params(improperp);
6383 }
#define DebugM(x, y)
Definition: Debug.h:75
int NumImproperParams
Definition: Parameters.h:334

◆ print_nbthole_pair_params()

void Parameters::print_nbthole_pair_params ( )

Definition at line 6428 of file Parameters.C.

References DebugM, and NumNbtholePairParams.

6429 {
6430  DebugM(3,NumNbtholePairParams << " NBTHOLE PAIR PARAMETERS\n" \
6431  << "*****************************************" );
6432 
6433  traverse_nbthole_pair_params(nbthole_pairp);
6434 }
#define DebugM(x, y)
Definition: Debug.h:75
int NumNbtholePairParams
Definition: Parameters.h:343

◆ print_param_summary()

void Parameters::print_param_summary ( )

Definition at line 6478 of file Parameters.C.

References endi(), iINFO(), iout, NumAngleParams, NumBondParams, NumCosAngles, NumCrosstermParams, NumDihedralParams, NumImproperParams, NumNbtholePairParams, NumVdwPairParams, and NumVdwParams.

Referenced by NamdState::loadStructure().

6479 {
6480  iout << iINFO << "SUMMARY OF PARAMETERS:\n"
6481  << iINFO << NumBondParams << " BONDS\n"
6482  << iINFO << NumAngleParams << " ANGLES\n" << endi;
6483  if (cosAngles) {
6484  iout << iINFO << " " << (NumAngleParams - NumCosAngles) << " HARMONIC\n"
6485  << iINFO << " " << NumCosAngles << " COSINE-BASED\n" << endi;
6486  }
6487  iout << iINFO << NumDihedralParams << " DIHEDRAL\n"
6488  << iINFO << NumImproperParams << " IMPROPER\n"
6489  << iINFO << NumCrosstermParams << " CROSSTERM\n"
6490  << iINFO << NumVdwParams << " VDW\n"
6491  << iINFO << NumVdwPairParams << " VDW_PAIRS\n"
6492  << iINFO << NumNbtholePairParams << " NBTHOLE_PAIRS\n" << endi;
6493 }
std::ostream & iINFO(std::ostream &s)
Definition: InfoStream.C:81
int NumBondParams
Definition: Parameters.h:330
int NumVdwParams
Definition: Parameters.h:339
int NumVdwPairParams
Definition: Parameters.h:342
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
#define iout
Definition: InfoStream.h:51
int NumAngleParams
Definition: Parameters.h:331
int NumDihedralParams
Definition: Parameters.h:333
int NumNbtholePairParams
Definition: Parameters.h:343
int NumImproperParams
Definition: Parameters.h:334
int NumCosAngles
Definition: Parameters.h:332
int NumCrosstermParams
Definition: Parameters.h:335

◆ print_vdw_pair_params()

void Parameters::print_vdw_pair_params ( )

Definition at line 6411 of file Parameters.C.

References DebugM, and NumVdwPairParams.

6412 {
6413  DebugM(3,NumVdwPairParams << " vdW PAIR PARAMETERS\n" \
6414  << "*****************************************" );
6415 
6416  traverse_vdw_pair_params(vdw_pairp);
6417 }
#define DebugM(x, y)
Definition: Debug.h:75
int NumVdwPairParams
Definition: Parameters.h:342

◆ print_vdw_params()

void Parameters::print_vdw_params ( )

Definition at line 6394 of file Parameters.C.

References DebugM, and NumVdwParams.

6395 {
6396  DebugM(3,NumVdwParams << " vdW PARAMETERS\n" \
6397  << "*****************************************" );
6398 
6399  traverse_vdw_params(vdwp);
6400 }
int NumVdwParams
Definition: Parameters.h:339
#define DebugM(x, y)
Definition: Debug.h:75

◆ read_charmm_parameter_file()

void Parameters::read_charmm_parameter_file ( char *  fname)

Definition at line 567 of file Parameters.C.

References endi(), iout, iWARN(), NAMD_blank_string(), NAMD_die(), NAMD_find_first_word(), NAMD_read_line(), NumAngleParams, NumBondParams, NumCrosstermParams, NumDihedralParams, NumImproperParams, NumNbtholePairParams, NumTablePairParams, NumVdwPairParams, NumVdwParams, table_ener, and TRUE.

Referenced by Parameters().

569 {
570  int par_type=0; // What type of parameter are we currently
571  // dealing with? (vide infra)
572  int skipline; // skip this line?
573  int skipall = 0; // skip rest of file;
574  char buffer[512]; // Buffer to store each line of the file
575  char first_word[512]; // First word of the current line
576  FILE *pfile; // File descriptor for the parameter file
577 
578  /* Check to make sure that we haven't previously been told */
579  /* that all the files were read */
580  if (AllFilesRead)
581  {
582  NAMD_die("Tried to read another parameter file after being told that all files were read!");
583  }
584 
585  /* Try and open the file */
586  if ( (pfile = fopen(fname, "r")) == NULL)
587  {
588  char err_msg[512];
589 
590  snprintf(err_msg, sizeof(err_msg),
591  "UNABLE TO OPEN CHARMM PARAMETER FILE %s\n", fname);
592  NAMD_die(err_msg);
593  }
594 
595  /* Keep reading in lines until we hit the EOF */
596  while (NAMD_read_line(pfile, buffer) != -1)
597  {
598  /* Get the first word of the line */
599  NAMD_find_first_word(buffer, first_word);
600  skipline=0;
601 
602  /* First, screen out things that we ignore. */
603  /* blank lines, lines that start with '!' or '*', lines that */
604  /* start with "END". */
605  if (!NAMD_blank_string(buffer) &&
606  (strncmp(first_word, "!", 1) != 0) &&
607  (strncmp(first_word, "*", 1) != 0) &&
608  (strncasecmp(first_word, "END", 3) != 0))
609  {
610  if ( skipall ) {
611  iout << iWARN << "SKIPPING PART OF PARAMETER FILE AFTER RETURN STATEMENT\n" << endi;
612  break;
613  }
614  /* Now, determine the apropriate parameter type. */
615  if (strncasecmp(first_word, "bond", 4)==0)
616  {
617  par_type=1; skipline=1;
618  }
619  else if (strncasecmp(first_word, "angl", 4)==0)
620  {
621  par_type=2; skipline=1;
622  }
623  else if (strncasecmp(first_word, "thet", 4)==0)
624  {
625  par_type=2; skipline=1;
626  }
627  else if (strncasecmp(first_word, "dihe", 4)==0)
628  {
629  par_type=3; skipline=1;
630  }
631  else if (strncasecmp(first_word, "phi", 3)==0)
632  {
633  par_type=3; skipline=1;
634  }
635  else if (strncasecmp(first_word, "impr", 4)==0)
636  {
637  par_type=4; skipline=1;
638  }
639  else if (strncasecmp(first_word, "imph", 4)==0)
640  {
641  par_type=4; skipline=1;
642  }
643  else if (strncasecmp(first_word, "nbon", 4)==0)
644  {
645  par_type=5; skipline=1;
646  }
647  else if (strncasecmp(first_word, "nonb", 4)==0)
648  {
649  par_type=5; skipline=1;
650  }
651  else if (strncasecmp(first_word, "nbfi", 4)==0)
652  {
653  par_type=6; skipline=1;
654  }
655  else if (strncasecmp(first_word, "hbon", 4)==0)
656  {
657  par_type=7; skipline=1;
658  }
659  else if (strncasecmp(first_word, "cmap", 4)==0)
660  {
661  par_type=8; skipline=1;
662  }
663  else if (strncasecmp(first_word, "nbta", 4)==0)
664  {
665  par_type=9; skipline=1;
666  }
667  else if (strncasecmp(first_word, "thol", 4)==0)
668  {
669  par_type=10; skipline=1;
670  }
671  else if (strncasecmp(first_word, "atom", 4)==0)
672  {
673  par_type=11; skipline=1;
674  }
675  else if (strncasecmp(first_word, "ioformat", 8)==0)
676  {
677  skipline=1;
678  }
679  else if (strncasecmp(first_word, "read", 4)==0)
680  {
681  skip_stream_read(buffer, pfile); skipline=1;
682  }
683  else if (strncasecmp(first_word, "return", 4)==0)
684  {
685  skipall=1; skipline=1;
686  }
687  else if ((strncasecmp(first_word, "nbxm", 4) == 0) ||
688  (strncasecmp(first_word, "grou", 4) == 0) ||
689  (strncasecmp(first_word, "cdie", 4) == 0) ||
690  (strncasecmp(first_word, "shif", 4) == 0) ||
691  (strncasecmp(first_word, "vgro", 4) == 0) ||
692  (strncasecmp(first_word, "vdis", 4) == 0) ||
693  (strncasecmp(first_word, "vswi", 4) == 0) ||
694  (strncasecmp(first_word, "cutn", 4) == 0) ||
695  (strncasecmp(first_word, "ctof", 4) == 0) ||
696  (strncasecmp(first_word, "cton", 4) == 0) ||
697  (strncasecmp(first_word, "eps", 3) == 0) ||
698  (strncasecmp(first_word, "e14f", 4) == 0) ||
699  (strncasecmp(first_word, "wmin", 4) == 0) ||
700  (strncasecmp(first_word, "aexp", 4) == 0) ||
701  (strncasecmp(first_word, "rexp", 4) == 0) ||
702  (strncasecmp(first_word, "haex", 4) == 0) ||
703  (strncasecmp(first_word, "aaex", 4) == 0) ||
704  (strncasecmp(first_word, "noac", 4) == 0) ||
705  (strncasecmp(first_word, "hbno", 4) == 0) ||
706  (strncasecmp(first_word, "cuth", 4) == 0) ||
707  (strncasecmp(first_word, "ctof", 4) == 0) ||
708  (strncasecmp(first_word, "cton", 4) == 0) ||
709  (strncasecmp(first_word, "cuth", 4) == 0) ||
710  (strncasecmp(first_word, "ctof", 4) == 0) ||
711  (strncasecmp(first_word, "cton", 4) == 0) )
712  {
713  if ((par_type != 5) && (par_type != 6) && (par_type != 7) && (par_type != 9))
714  {
715  char err_msg[512];
716 
717  snprintf(err_msg, sizeof(err_msg),
718  "ERROR IN CHARMM PARAMETER FILE %s\nLINE=*%s*", fname, buffer);
719  NAMD_die(err_msg);
720  }
721  else
722  {
723  skipline = 1;
724  }
725  }
726  else if (par_type == 0)
727  {
728  /* This is an unknown paramter. */
729  /* This is BAD */
730  char err_msg[512];
731 
732  snprintf(err_msg, sizeof(err_msg),
733  "UNKNOWN PARAMETER IN CHARMM PARAMETER FILE %s\nLINE=*%s*",
734  fname, buffer);
735  NAMD_die(err_msg);
736  }
737  }
738  else
739  {
740  skipline=1;
741  }
742 
743  if ( (par_type != 0) && (!skipline) )
744  {
745  /* Now, call the appropriate function based */
746  /* on the type of parameter we have */
747  /* I know, this should really be a switch ... */
748  if (par_type == 1)
749  {
750  add_bond_param(buffer, TRUE);
751  NumBondParams++;
752  }
753  else if (par_type == 2)
754  {
755  add_angle_param(buffer);
756  NumAngleParams++;
757  }
758  else if (par_type == 3)
759  {
760  add_dihedral_param(buffer, pfile);
762  }
763  else if (par_type == 4)
764  {
765  add_improper_param(buffer, pfile);
767  }
768  else if (par_type == 5)
769  {
770  add_vdw_param(buffer);
771  NumVdwParams++;
772  }
773  else if (par_type == 6)
774  {
775  add_vdw_pair_param(buffer);
776  NumVdwPairParams++;
777  }
778  else if (par_type == 7)
779  {
780  add_hb_pair_param(buffer);
781  }
782  else if (par_type == 8)
783  {
784  add_crossterm_param(buffer, pfile);
786  }
787  else if (par_type == 9)
788  {
789 
790  if (table_ener == NULL) {
791  continue;
792  }
793 
794  add_table_pair_param(buffer);
796  }
797  else if (par_type == 10)
798  {
799  add_nbthole_pair_param(buffer);
801  }
802  else if (par_type == 11)
803  {
804  if ( strncasecmp(first_word, "mass", 4) != 0 ) {
805  char err_msg[512];
806  snprintf(err_msg, sizeof(err_msg),
807  "UNKNOWN PARAMETER IN CHARMM PARAMETER FILE %s\nLINE=*%s*",
808  fname, buffer);
809  NAMD_die(err_msg);
810  }
811  }
812  else
813  {
814  /* This really should not occour! */
815  /* This is an internal error. */
816  /* This is VERY BAD */
817  char err_msg[512];
818 
819  snprintf(err_msg, sizeof(err_msg),
820  "INTERNAL ERROR IN CHARMM PARAMETER FILE %s\nLINE=*%s*",
821  fname, buffer);
822  NAMD_die(err_msg);
823  }
824  }
825  }
826  /* Close the file */
827  fclose(pfile);
828 
829  return;
830 }
int NumTablePairParams
Definition: Parameters.h:344
int NumBondParams
Definition: Parameters.h:330
int NAMD_read_line(FILE *fd, char *buf, int bufsize)
Definition: strlib.C:38
int NumVdwParams
Definition: Parameters.h:339
int NumVdwPairParams
Definition: Parameters.h:342
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
std::ostream & iWARN(std::ostream &s)
Definition: InfoStream.C:82
#define iout
Definition: InfoStream.h:51
void NAMD_find_first_word(char *source, char *word)
Definition: strlib.C:258
int NumAngleParams
Definition: Parameters.h:331
int NumDihedralParams
Definition: Parameters.h:333
int NumNbtholePairParams
Definition: Parameters.h:343
int NAMD_blank_string(char *str)
Definition: strlib.C:222
int NumImproperParams
Definition: Parameters.h:334
int NumCrosstermParams
Definition: Parameters.h:335
void NAMD_die(const char *err_msg)
Definition: common.C:147
BigReal * table_ener
Definition: Parameters.h:325
#define TRUE
Definition: common.h:128

◆ read_ener_table()

void Parameters::read_ener_table ( SimParameters simParams)

Definition at line 8527 of file Parameters.C.

References endi(), iout, NAMD_die(), namdnearbyint, numenerentries, read_energy_type(), read_energy_type_bothcubspline(), simParams, table_ener, table_types, and tablenumtypes.

Referenced by Parameters().

8527  {
8528  char* table_file = simParams->tabulatedEnergiesFile;
8529  char* interp_type = simParams->tableInterpType;
8530  FILE* enertable;
8531  enertable = fopen(table_file, "r");
8532 
8533  if (enertable == NULL) {
8534  NAMD_die("ERROR: Could not open energy table file!\n");
8535  }
8536 
8537  char tableline[121];
8538  char* newtypename;
8539  int numtypes;
8540  int atom1;
8541  int atom2;
8542  int distbin;
8543  int readcount;
8544  Real dist;
8545  Real energy;
8546  Real force;
8547  Real table_spacing;
8548  Real maxdist;
8549 
8550 /* First find the header line and set the variables we need */
8551  iout << "Beginning table read\n" << endi;
8552  while(fgets(tableline,120,enertable)) {
8553  if (strncmp(tableline,"#",1)==0) {
8554  continue;
8555  }
8556  readcount = sscanf(tableline, "%i %f %f", &numtypes, &table_spacing, &maxdist);
8557  if (readcount != 3) {
8558  NAMD_die("ERROR: Couldn't parse table header line\n");
8559  }
8560  break;
8561  }
8562 
8563  if (maxdist < simParams->cutoff) {
8564  NAMD_die("Tabulated energies must at least extend to the cutoff distance\n");
8565  }
8566 
8567  if (maxdist > simParams->cutoff) {
8568  iout << "Info: Reducing max table size to match nonbond cutoff\n";
8569  maxdist = ceil(simParams->cutoff);
8570  }
8571 
8572 /* Now allocate memory for the table; we know what we should be getting */
8573  numenerentries = 2 * numtypes * int (namdnearbyint(maxdist/table_spacing) + 1);
8574  //Set up a full energy lookup table from a file
8575  //Allocate the table; layout is atom1 x atom2 x distance energy force
8576  fprintf(stdout, "Table has %i entries\n",numenerentries);
8577  //iout << "Allocating original energy table\n" << endi;
8578  if ( table_ener ) delete [] table_ener;
8580  if ( table_types ) delete [] table_types;
8581  table_types = new char*[numtypes];
8582 
8583 /* Finally, start reading the table */
8584  int numtypesread = 0; //Number of types read so far
8585 
8586  while(fgets(tableline,120,enertable)) {
8587  if (strncmp(tableline,"#",1)==0) {
8588  continue;
8589  }
8590  if (strncmp(tableline,"TYPE",4)==0) {
8591  // Read a new type
8592  newtypename = new char[5];
8593  int readcount = sscanf(tableline, "%*s %s", newtypename);
8594  if (readcount != 1) {
8595  NAMD_die("Couldn't read interaction type from TYPE line\n");
8596  }
8597 // printf("Setting table_types[%i] to %s\n", numtypesread, newtypename);
8598  table_types[numtypesread] = newtypename;
8599 
8600  if (numtypesread == numtypes) {
8601  NAMD_die("Error: Number of types in table doesn't match table header\n");
8602  }
8603 
8604  // Read the current energy type with the proper interpolation
8605  if (!strncasecmp(interp_type, "linear", 6)) {
8606  if (read_energy_type(enertable, numtypesread, table_ener, table_spacing, maxdist) != 0) {
8607  char err_msg[512];
8608  snprintf(err_msg, sizeof(err_msg),
8609  "Failed to read table energy (linear) type %s\n", newtypename);
8610  NAMD_die(err_msg);
8611  }
8612  } else if (!strncasecmp(interp_type, "cubic", 5)) {
8613  if (read_energy_type_bothcubspline(enertable, numtypesread, table_ener, table_spacing, maxdist) != 0) {
8614  char err_msg[512];
8615  snprintf(err_msg, sizeof(err_msg),
8616  "Failed to read table energy (cubic) type %s\n", newtypename);
8617  NAMD_die(err_msg);
8618  }
8619  } else {
8620  NAMD_die("Table interpolation type must be linear or cubic\n");
8621  }
8622 
8623  numtypesread++;
8624  continue;
8625  }
8626  //char err_msg[512];
8627  //snprintf(err_msg, sizeof(err_msg),
8628  // "Unrecognized line in energy table file: %s\n", tableline);
8629  //NAMD_die(err_msg);
8630  }
8631 
8632  // See if we got what we expected
8633  if (numtypesread != numtypes) {
8634  char err_msg[512];
8635  snprintf(err_msg, sizeof(err_msg),
8636  "ERROR: Expected %i tabulated energy types but got %i\n",
8637  numtypes, numtypesread);
8638  NAMD_die(err_msg);
8639  }
8640 
8641  // Move the necessary information into simParams
8642  simParams->tableNumTypes = numtypes;
8643  simParams->tableSpacing = table_spacing;
8644  simParams->tableMaxDist = maxdist;
8645  tablenumtypes = numtypes;
8646 
8647  /*
8648 xxxxxx
8649  int numtypes = simParams->tableNumTypes;
8650 
8651  //This parameter controls the table spacing
8652  BigReal table_spacing = 0.01;
8653  BigReal maxdist = 20.0;
8654  if (maxdist > simParams->cutoff) {
8655  iout << "Info: Reducing max table size to match nonbond cutoff\n";
8656  maxdist = ceil(simParams->cutoff);
8657  }
8658 
8659  numenerentries = (numtypes + 1) * numtypes * int (ceil(maxdist/table_spacing));
8660 // fprintf(stdout, "Table arithmetic: maxdist %f, table_spacing %f, numtypes %i, numentries %i\n", maxdist, table_spacing, numtypes, numenerentries);
8661  columnsize = 2 * namdnearbyint(maxdist/table_spacing);
8662  rowsize = numtypes * columnsize;
8663  //Set up a full energy lookup table from a file
8664  //Allocate the table; layout is atom1 x atom2 x distance energy force
8665  fprintf(stdout, "Table has %i entries\n",numenerentries);
8666  //iout << "Allocating original energy table\n" << endi;
8667  if ( table_ener ) delete [] table_ener;
8668  table_ener = new Real[numenerentries];
8669  //
8670  //Set sentinel values for uninitialized table energies
8671  for (int i=0 ; i<numenerentries ; i++) {
8672  table_ener[i] = 1337.0;
8673  }
8674  Real compval = 1337.0;
8675 
8676  // iout << "Entering table reading\n" << endi;
8677  //iout << "Finished allocating table\n" << endi;
8678 
8679  //Counter to make sure we read the right number of energy entries
8680  int numentries = 0;
8681 
8682  //Now, start reading from the file
8683  char* table_file = simParams->tabulatedEnergiesFile;
8684  FILE* enertable;
8685  enertable = fopen(table_file, "r");
8686 
8687  if (enertable == NULL) {
8688  NAMD_die("ERROR: Could not open energy table file!\n");
8689  }
8690 
8691  char tableline[121];
8692  int atom1;
8693  int atom2;
8694  int distbin;
8695  Real dist;
8696  Real energy;
8697  Real force;
8698 
8699  iout << "Beginning table read\n" << endi;
8700  //Read the table entries
8701  while(fgets(tableline,120,enertable)) {
8702 // IOut << "Processing line " << tableline << "\n" << endi;
8703  if (strncmp(tableline,"#",1)==0) {
8704  continue;
8705  }
8706 
8707 
8708  sscanf(tableline, "%i %i %f %f %f\n", &atom1, &atom2, &dist, &energy, &force);
8709  distbin = int(namdnearbyint(dist/table_spacing));
8710 // fprintf(stdout, "Working on atoms %i and %i at distance %f\n",atom1,atom2,dist);
8711  if ((atom2 > atom1) || (distbin > int(namdnearbyint(maxdist/table_spacing)))) {
8712 // fprintf(stdout,"Rejected\n");
8713 // fprintf(stdout, "Error: Throwing out energy line beyond bounds\n");
8714  // fprintf(stdout, "Bad line: Atom 1: %i Atom 2: %i Distance Bin: %i Max Distance Bin: %i \n", atom1, atom2, distbin, int(namdnearbyint(maxdist/table_spacing)));
8715  } else {
8716  //The magic formula for the number of columns from previous rows
8717  //in the triangular matrix is (2ni+i-i**2)/2
8718  //Here n is the number of types, and i is atom2
8719 // fprintf(stdout, "Input: atom1 %f atom2 %f columnsize %f \n", float(atom1), float(atom2), float(columnsize));
8720 // fprintf(stdout, "Testing arithmetic: Part1: %i Part2: %i Part3: %i Total: %i\n", columnsize*((2*numtypes*atom2 + atom2 - atom2*atom2)/2), columnsize*(atom1-atom2), 2*distbin, columnsize*((2*numtypes*atom2 + atom2 - atom2*atom2)/2) + columnsize*(atom1-atom2) + 2*distbin - 2);
8721  int eneraddress = columnsize*((2*numtypes*atom2 + atom2 - atom2*atom2)/2) + columnsize*(atom1-atom2) + 2*distbin - 2;
8722  int forceaddress = eneraddress + 1;
8723 // fprintf(stdout, "Tableloc: %i Atom 1: %i Atom 2: %i Distance Bin: %i Energy: %f Force: %f\n", eneraddress, atom1, atom2, distbin, table_ener[eneraddress], table_ener[forceaddress]);
8724  fflush(stdout);
8725 // fprintf(stdout, "Checking for dupes: Looking at: %f %f \n", table_ener[eneraddress], table_ener[forceaddress]);
8726  if ((table_ener[eneraddress] == compval && table_ener[forceaddress] == compval)) {
8727  numentries++;
8728  table_ener[eneraddress] = energy;
8729  table_ener[forceaddress] = force;
8730 // fprintf(stdout, "Tableloc: %i Atom 1: %i Atom 2: %i Distance Bin: %i Energy: %f Force: %f\n", eneraddress, atom1, atom2, distbin, table_ener[eneraddress], table_ener[forceaddress]);
8731  //table_ener[rowsize*atom2 + columnsize*atom1 + 2*distbin] = energy;
8732  //table_ener[rowsize*atom2 + columnsize*atom1 + 2*distbin + 1] = force;
8733 // fflush(stdout);
8734  } else {
8735 // fprintf(stdout,"Rejecting duplicate entry\n");
8736  }
8737  }
8738  // iout << "Done with line\n"<< endi;
8739  }
8740 
8741  // int should = numtypes * numtypes * (maxdist/table_spacing);
8742  // cout << "Entries: " << numentries << " should be " << should << "\n" << endi;
8743 // int exptypes = ceil((numtypes+1) * numtypes * (maxdist/table_spacing));
8744 //fprintf(stdout,"numtypes: %i maxdist: %f table_spacing: %f exptypes: %i\n",numtypes,maxdist,table_spacing);
8745  if (numentries != int(numenerentries/2)) {
8746  fprintf(stdout,"ERROR: Expected %i entries but got %i\n",numenerentries/2, numentries);
8747  NAMD_die("Number of energy table entries did not match expected value\n");
8748  }
8749  // iout << "Done with table\n"<< endi;
8750  fprintf(stdout, "Numenerentries: %i\n",numenerentries/2);
8751  */
8752 } /* END of function read_ener_table */
int numenerentries
Definition: Parameters.h:322
#define namdnearbyint(x)
Definition: common.h:85
static char ** table_types
Definition: Parameters.C:39
float Real
Definition: common.h:118
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
#define iout
Definition: InfoStream.h:51
int read_energy_type(FILE *, const int, BigReal *, const float, const float)
Definition: Parameters.C:9252
void NAMD_die(const char *err_msg)
Definition: common.C:147
#define simParams
Definition: Output.C:129
BigReal * table_ener
Definition: Parameters.h:325
int read_energy_type_bothcubspline(FILE *, const int, BigReal *, const float, const float)
Definition: Parameters.C:8775
int tablenumtypes
Definition: Parameters.h:329
double BigReal
Definition: common.h:123

◆ read_energy_type()

int Parameters::read_energy_type ( FILE *  enertable,
const int  typeindex,
BigReal table_ener,
const float  table_spacing,
const float  maxdist 
)

Definition at line 9252 of file Parameters.C.

References NAMD_die(), namdnearbyint, and table_ener.

Referenced by read_ener_table().

9252  {
9253 
9254  char tableline[120];
9255 
9256  /* Last values read from table */
9257  BigReal readdist;
9258  BigReal readener;
9259  BigReal readforce;
9260  BigReal lastdist;
9261  BigReal lastener;
9262  BigReal lastforce;
9263  readdist = -1.0;
9264  readener = 0.0;
9265  readforce = 0.0;
9266 
9267  /* Keep track of where in the table we are */
9268  float currdist;
9269  int distbin;
9270  currdist = -1.0;
9271  distbin = -1;
9272 
9273  while(fgets(tableline,120,enertable) && distbin <= (int) (namdnearbyint(maxdist / table_spacing) + 1)) {
9274  printf("At distance %f + %f vs. %f\n", currdist, table_spacing, maxdist);
9275  if (strncmp(tableline,"#",1)==0) {
9276  continue;
9277  }
9278  if (strncmp(tableline,"TYPE",4)==0) {
9279  break;
9280  }
9281 
9282  // Read an energy line from the table
9283  lastdist = readdist;
9284  lastener = readener;
9285  lastforce = readforce;
9286  int readcount = sscanf(tableline, "%lf %lf %lf", &readdist, &readener, &readforce);
9287  if (distbin == -1) {
9288  if (readdist != 0.0) {
9289  NAMD_die("ERROR: Energy/force tables must start at d=0.0\n");
9290  } else {
9291  distbin = 0;
9292  continue;
9293  }
9294  }
9295  // printf("Read an energy line: %f %f %f\n", readdist, readener, readforce);
9296  if (readcount != 3) {
9297  char err_msg[512];
9298  snprintf(err_msg, sizeof(err_msg),
9299  "ERROR: Failed to parse table line %s!\n", tableline);
9300  NAMD_die(err_msg);
9301  }
9302 
9303  //Sanity check the current entry
9304  if (readdist < lastdist) {
9305  NAMD_die("ERROR: Encountered badly ordered entries in energy table!\n");
9306  }
9307 
9308  currdist = lastdist;
9309 
9310  while (currdist <= readdist && distbin <= (int) (namdnearbyint(maxdist / table_spacing))) {
9311  distbin = (int) (namdnearbyint(currdist / table_spacing));
9312  int table_loc = 2 * (distbin + (typeindex * (1 + (int) namdnearbyint(maxdist / table_spacing))));
9313  printf("Doing interpolation for energy between %f %f and %f %f: Dist %f\n", readener, readdist, lastener, lastdist, currdist);
9314  table_ener[table_loc] = interp_lin(readener, lastener, readdist, lastdist, currdist);
9315  table_ener[table_loc + 1] = interp_lin(readforce, lastforce, readdist, lastdist, currdist);
9316  printf("Adding energy/force entry: %f %f in distbin %i (distance %f) to address %i/%i\n", table_ener[table_loc], table_ener[table_loc + 1], distbin, currdist, table_loc, table_loc + 1);
9317  currdist += table_spacing;
9318  distbin++;
9319  }
9320  }
9321 
9322  // Go back one line, since we should now be into the next TYPE block
9323  fseek(enertable, -1 * (long) strlen(tableline), SEEK_CUR);
9324 
9325  // Clean up and make sure everything worked ok
9326  distbin--;
9327  printf("Testing: %i vs %i (from %f / %f)\n", distbin, (int) (namdnearbyint(maxdist / table_spacing)), maxdist, table_spacing);
9328  if (distbin != (int) (namdnearbyint(maxdist / table_spacing))) return 1;
9329  return 0;
9330 }
#define namdnearbyint(x)
Definition: common.h:85
void NAMD_die(const char *err_msg)
Definition: common.C:147
BigReal * table_ener
Definition: Parameters.h:325
double BigReal
Definition: common.h:123

◆ read_energy_type_bothcubspline()

int Parameters::read_energy_type_bothcubspline ( FILE *  enertable,
const int  typeindex,
BigReal table_ener,
const float  table_spacing,
const float  maxdist 
)

Definition at line 8775 of file Parameters.C.

References INDEX, NAMD_die(), namdnearbyint, and table_ener.

Referenced by read_ener_table().

8775  {
8776 
8777  char tableline[120];
8778  int i,j;
8779 
8780  /* Last values read from table */
8781  BigReal readdist;
8782  BigReal readener;
8783  BigReal readforce;
8784  BigReal spacing;
8785 // BigReal readforce;
8786  BigReal lastdist;
8787 // BigReal lastener;
8788 // BigReal lastforce;
8789 // readdist = -1.0;
8790 // readener = 0.0;
8791 // readforce = 0.0;
8792 
8793  /* Create arrays for holding the input values */
8794  std::vector<BigReal> dists;
8795  std::vector<BigReal> enervalues;
8796  std::vector<BigReal> forcevalues;
8797  int numentries = 0;
8798 
8799 
8800  /* Keep track of where in the table we are */
8801  BigReal currdist;
8802  int distbin;
8803  currdist = 0.0;
8804  lastdist = -1.0;
8805  distbin = 0;
8806 
8807  // Read all of the values first -- we'll interpolate later
8808  while(fgets(tableline,120,enertable) && distbin <= (int) (namdnearbyint(maxdist / table_spacing) + 1)) {
8809  if (strncmp(tableline,"#",1)==0) {
8810  continue;
8811  }
8812  if (strncmp(tableline,"TYPE",4)==0) {
8813  fseek(enertable, -1 * (long) strlen(tableline), SEEK_CUR);
8814  break;
8815  }
8816 
8817  // Read an energy line from the table
8818  int readcount = sscanf(tableline, "%lf %lf %lf", &readdist, &readener, &readforce);
8819 
8820  //printf("Read an energy line: %g %g %g\n", readdist, readener, readforce);
8821  if (readcount != 3) {
8822  char err_msg[512];
8823  snprintf(err_msg, sizeof(err_msg),
8824  "ERROR: Failed to parse table line %s!\n", tableline);
8825  NAMD_die(err_msg);
8826  }
8827 
8828  //Sanity check the current entry
8829  if (readdist < lastdist) {
8830  NAMD_die("ERROR: Encountered badly ordered entries in energy table!\n");
8831  }
8832 
8833  lastdist = readdist;
8834  dists.push_back(readdist);
8835  enervalues.push_back(readener);
8836  forcevalues.push_back(readforce);
8837  numentries++;
8838  }
8839 
8840  // Check the spacing and make sure it is uniform
8841  if (dists[0] != 0.0) {
8842  NAMD_die("ERROR: First data point for energy table must be at r=0\n");
8843  }
8844  spacing = dists[1] - dists[0];
8845  for (i=2; i<(numentries - 1); i++) {
8846  BigReal myspacing;
8847  myspacing = dists[i] - dists[i-1];
8848  if (fabs(myspacing - spacing) > 0.00001) {
8849  printf("Bad spacing in table: %f should be %f (between distances %f and %f)\n", myspacing, spacing, dists[i-1], dists[i]);
8850  NAMD_die("ERROR: Nonuniform table encountered on cubic interpolation. Use a uniformly spaced table or switch to linear interpolation.\n");
8851  }
8852  }
8853 
8854 // Perform cubic spline interpolation to get the energies and forces
8855 
8856  /* allocate spline coefficient matrix */
8857  // xe and xf / be and bf for energies and forces, respectively
8858  double* m = new double[numentries*numentries];
8859  double* xe = new double[numentries];
8860  double* xf = new double[numentries];
8861  double* be = new double[numentries];
8862  double* bf = new double[numentries];
8863 
8864  be[0] = 3 * (enervalues[1] - enervalues[0]);
8865  for (i=1; i < (numentries - 1); i++) {
8866 // printf("Control point %i at %f\n", i, enervalues[i]);
8867  be[i] = 3 * (enervalues[i+1] - enervalues[i-1]);
8868 // printf("be is %f\n", be[i]);
8869  }
8870  be[numentries - 1] = 3 * (enervalues[numentries - 1] - enervalues[numentries - 2]);
8871 
8872  bf[0] = 3 * (forcevalues[1] - forcevalues[0]);
8873  for (i=1; i < (numentries - 1); i++) {
8874 // printf("Control point %i at %f\n", i, forcevalues[i]);
8875  bf[i] = 3 * (forcevalues[i+1] - forcevalues[i-1]);
8876 // printf("bf is %f\n", bf[i]);
8877  }
8878  bf[numentries - 1] = 3 * (forcevalues[numentries - 1] - forcevalues[numentries - 2]);
8879 
8880  memset(m,0,numentries*numentries*sizeof(double));
8881 
8882  /* initialize spline coefficient matrix */
8883  m[0] = 2;
8884  for (i = 1; i < numentries; i++) {
8885  m[INDEX(numentries,i-1,i)] = 1;
8886  m[INDEX(numentries,i,i-1)] = 1;
8887  m[INDEX(numentries,i,i)] = 4;
8888  }
8889  m[INDEX(numentries,numentries-1,numentries-1)] = 2;
8890 
8891  /* Now we need to solve the equation M X = b for X */
8892  // Do this simultaneously for energy and force -- ONLY because we use the same matrix
8893 
8894  //Put m in upper triangular form and apply corresponding operations to b
8895  for (i=0; i<numentries; i++) {
8896  // zero the ith column in all rows below i
8897  const BigReal baseval = m[INDEX(numentries,i,i)];
8898  for (j=i+1; j<numentries; j++) {
8899  const BigReal myval = m[INDEX(numentries,j,i)];
8900  const BigReal factor = myval / baseval;
8901 
8902  for (int k=i; k<numentries; k++) {
8903  const BigReal subval = m[INDEX(numentries,i,k)];
8904  m[INDEX(numentries,j,k)] -= (factor * subval);
8905  }
8906 
8907  be[j] -= (factor * be[i]);
8908  bf[j] -= (factor * bf[i]);
8909 
8910  }
8911  }
8912 
8913  //Now work our way diagonally up from the bottom right to assign values to X
8914  for (i=numentries-1; i>=0; i--) {
8915 
8916  //Subtract the effects of previous columns
8917  for (j=i+1; j<numentries; j++) {
8918  be[i] -= ( m[INDEX(numentries,i,j)] * xe[j] );
8919  bf[i] -= ( m[INDEX(numentries,i,j)] * xf[j] );
8920  }
8921 
8922  xe[i] = be[i] / m[INDEX(numentries,i,i)];
8923  xf[i] = bf[i] / m[INDEX(numentries,i,i)];
8924 
8925  }
8926 
8927  // We now have the coefficient information we need to make the table
8928  // Now interpolate on each interval we want
8929 
8930  distbin = 0;
8931  int entriesperseg = (int) ceil(spacing / table_spacing);
8932  int table_prefix = 2 * typeindex * (int) (namdnearbyint(maxdist / table_spacing) + 1);
8933 
8934  for (i=0; i<numentries-1; i++) {
8935  BigReal Ae,Be,Ce,De;
8936  BigReal Af,Bf,Cf,Df;
8937  currdist = dists[i];
8938 
8939 // printf("Interpolating on interval %i\n", i);
8940 
8941  // Set up the coefficients for this section
8942  Ae = enervalues[i];
8943  Be = xe[i];
8944  Ce = 3 * (enervalues[i+1] - enervalues[i]) - (2 * xe[i]) - xe[i+1];
8945  De = 2 * (enervalues[i] - enervalues[i+1]) + xe[i] + xe[i+1];
8946 
8947  Af = forcevalues[i];
8948  Bf = xf[i];
8949  Cf = 3 * (forcevalues[i+1] - forcevalues[i]) - (2 * xf[i]) - xf[i+1];
8950  Df = 2 * (forcevalues[i] - forcevalues[i+1]) + xf[i] + xf[i+1];
8951 
8952  // Go over the region of interest and fill in the table
8953  for (j=0; j<entriesperseg; j++) {
8954  const BigReal mydist = currdist + (j * table_spacing);
8955  const BigReal mydistfrac = (float) j / (entriesperseg - 1);
8956  distbin = (int) namdnearbyint(mydist / table_spacing);
8957  if (distbin >= (int) namdnearbyint(maxdist / table_spacing)) break;
8958  BigReal energy;
8959  BigReal force;
8960 
8961  energy = Ae + (Be * mydistfrac) + (Ce * mydistfrac * mydistfrac) + (De * mydistfrac * mydistfrac * mydistfrac);
8962  force = Af + (Bf * mydistfrac) + (Cf * mydistfrac * mydistfrac) + (Df * mydistfrac * mydistfrac * mydistfrac);
8963 
8964 // printf("Adding energy/force entry %f / %f in bins %i / %i for distance %f (%f)\n", energy, force, (table_prefix + 2 * distbin), (table_prefix + 2 * distbin + 1), mydist, mydistfrac);
8965  table_ener[table_prefix + 2 * distbin] = energy;
8966  table_ener[table_prefix + 2 * distbin + 1] = force;
8967  distbin++;
8968  }
8969  if (currdist >= maxdist) break;
8970  }
8971 
8972  //The procedure above leaves out the last entry -- add it explicitly
8973  distbin = (int) namdnearbyint(maxdist / table_spacing);
8974 // printf("Adding energy/force entry %f / %f in bins %i / %i\n", enervalues[numentries - 1], 0.0, (table_prefix + 2 * distbin), (table_prefix + 2 * distbin + 1));
8975  table_ener[table_prefix + 2 * distbin] = enervalues[numentries - 1];
8976  table_ener[table_prefix + 2 * distbin + 1] = 0.0;
8977  distbin++;
8978 
8979 
8980  // Clean up and make sure everything worked ok
8981  delete m;
8982  delete xe;
8983  delete xf;
8984  delete be;
8985  delete bf;
8986  distbin--;
8987  printf("Testing: %i vs %i (from %f / %f)\n", distbin, (int) (namdnearbyint(maxdist / table_spacing)), maxdist, table_spacing);
8988  if (distbin != (int) (namdnearbyint(maxdist / table_spacing))) return 1;
8989  return 0;
8990 } /* end read_energy_type_bothcubspline */
#define namdnearbyint(x)
Definition: common.h:85
#define INDEX(ncols, i, j)
Definition: Parameters.C:35
void NAMD_die(const char *err_msg)
Definition: common.C:147
BigReal * table_ener
Definition: Parameters.h:325
double BigReal
Definition: common.h:123

◆ read_energy_type_cubspline()

int Parameters::read_energy_type_cubspline ( FILE *  enertable,
const int  typeindex,
BigReal table_ener,
const float  table_spacing,
const float  maxdist 
)

Definition at line 9012 of file Parameters.C.

References INDEX, NAMD_die(), namdnearbyint, and table_ener.

9012  {
9013 
9014  char tableline[120];
9015  int i,j;
9016 
9017  /* Last values read from table */
9018  BigReal readdist;
9019  BigReal readener;
9020  BigReal spacing;
9021 // BigReal readforce;
9022  BigReal lastdist;
9023 // BigReal lastener;
9024 // BigReal lastforce;
9025 // readdist = -1.0;
9026 // readener = 0.0;
9027 // readforce = 0.0;
9028 
9029  /* Create arrays for holding the input values */
9030  std::vector<BigReal> dists;
9031  std::vector<BigReal> enervalues;
9032  int numentries = 0;
9033 
9034 
9035  /* Keep track of where in the table we are */
9036  BigReal currdist;
9037  int distbin;
9038  currdist = 0.0;
9039  lastdist = -1.0;
9040  distbin = 0;
9041 
9042  // Read all of the values first -- we'll interpolate later
9043  while(fgets(tableline,120,enertable) && distbin <= (int) (namdnearbyint(maxdist / table_spacing) + 1)) {
9044  if (strncmp(tableline,"#",1)==0) {
9045  continue;
9046  }
9047  if (strncmp(tableline,"TYPE",4)==0) {
9048  fseek(enertable, -1 * (long) strlen(tableline), SEEK_CUR);
9049  break;
9050  }
9051 
9052  // Read an energy line from the table
9053  int readcount = sscanf(tableline, "%lf %lf", &readdist, &readener);
9054 
9055  // printf("Read an energy line: %f %f %f\n", readdist, readener, readforce);
9056  if (readcount != 2) {
9057  char err_msg[512];
9058  snprintf(err_msg, sizeof(err_msg),
9059  "ERROR: Failed to parse table line %s!\n", tableline);
9060  NAMD_die(err_msg);
9061  }
9062 
9063  //Sanity check the current entry
9064  if (readdist < lastdist) {
9065  NAMD_die("ERROR: Encountered badly ordered entries in energy table!\n");
9066  }
9067 
9068  lastdist = readdist;
9069  dists.push_back(readdist);
9070  enervalues.push_back(readener);
9071  numentries++;
9072  }
9073 
9074  // Check the spacing and make sure it is uniform
9075  if (dists[0] != 0.0) {
9076  NAMD_die("ERROR: First data point for energy table must be at r=0\n");
9077  }
9078  spacing = dists[1] - dists[0];
9079  for (i=2; i<(numentries - 1); i++) {
9080  BigReal myspacing;
9081  myspacing = dists[i] - dists[i-1];
9082  if (fabs(myspacing - spacing) > 0.00001) {
9083  printf("Bad spacing in table: %f should be %f (between distances %f and %f)\n", myspacing, spacing, dists[i-1], dists[i]);
9084  NAMD_die("ERROR: Nonuniform table encountered on cubic interpolation. Use a uniformly spaced table or switch to linear interpolation.\n");
9085  }
9086  }
9087 
9088 // Perform cubic spline interpolation to get the energies and forces
9089 
9090  /* allocate spline coefficient matrix */
9091  double* m = new double[numentries*numentries];
9092  double* x = new double[numentries];
9093  double* b = new double[numentries];
9094 
9095  b[0] = 3 * (enervalues[1] - enervalues[0]);
9096  for (i=1; i < (numentries - 1); i++) {
9097  printf("Control point %i at %f\n", i, enervalues[i]);
9098  b[i] = 3 * (enervalues[i+1] - enervalues[i-1]);
9099  printf("b is %f\n", b[i]);
9100  }
9101  b[numentries - 1] = 3 * (enervalues[numentries - 1] - enervalues[numentries - 2]);
9102 
9103  memset(m,0,numentries*numentries*sizeof(double));
9104 
9105  /* initialize spline coefficient matrix */
9106  m[0] = 2;
9107  for (i = 1; i < numentries; i++) {
9108  m[INDEX(numentries,i-1,i)] = 1;
9109  m[INDEX(numentries,i,i-1)] = 1;
9110  m[INDEX(numentries,i,i)] = 4;
9111  }
9112  m[INDEX(numentries,numentries-1,numentries-1)] = 2;
9113 
9114  /* Now we need to solve the equation M X = b for X */
9115 
9116  printf("Solving the matrix equation: \n");
9117 
9118  for (i=0; i<numentries; i++) {
9119  printf(" ( ");
9120  for (j=0; j<numentries; j++) {
9121  printf(" %6.3f,", m[INDEX(numentries, i, j)]);
9122  }
9123  printf(" ) ( D%-3i ) = ( %6.3f )\n", i, b[i]);
9124  }
9125 
9126  //Put m in upper triangular form and apply corresponding operations to b
9127  for (i=0; i<numentries; i++) {
9128  // zero the ith column in all rows below i
9129  const BigReal baseval = m[INDEX(numentries,i,i)];
9130  for (j=i+1; j<numentries; j++) {
9131  const BigReal myval = m[INDEX(numentries,j,i)];
9132  const BigReal factor = myval / baseval;
9133 
9134  for (int k=i; k<numentries; k++) {
9135  const BigReal subval = m[INDEX(numentries,i,k)];
9136  m[INDEX(numentries,j,k)] -= (factor * subval);
9137  }
9138 
9139  b[j] -= (factor * b[i]);
9140 
9141  }
9142  }
9143 
9144  printf(" In upper diagonal form, equation is:\n");
9145  for (i=0; i<numentries; i++) {
9146  printf(" ( ");
9147  for (j=0; j<numentries; j++) {
9148  printf(" %6.3f,", m[INDEX(numentries, i, j)]);
9149  }
9150  printf(" ) ( D%-3i ) = ( %6.3f )\n", i, b[i]);
9151  }
9152 
9153  //Now work our way diagonally up from the bottom right to assign values to X
9154  for (i=numentries-1; i>=0; i--) {
9155 
9156  //Subtract the effects of previous columns
9157  for (j=i+1; j<numentries; j++) {
9158  b[i] -= ( m[INDEX(numentries,i,j)] * x[j] );
9159  }
9160 
9161  x[i] = b[i] / m[INDEX(numentries,i,i)];
9162 
9163  }
9164 
9165  printf(" Solution vector is:\n\t(");
9166  for (i=0; i<numentries; i++) {
9167  printf(" %6.3f ", x[i]);
9168  }
9169  printf(" ) \n");
9170 
9171  // We now have the coefficient information we need to make the table
9172  // Now interpolate on each interval we want
9173 
9174  distbin = 0;
9175  int entriesperseg = (int) ceil(spacing / table_spacing);
9176  int table_prefix = 2 * typeindex * (int) (namdnearbyint(maxdist / table_spacing) + 1);
9177 
9178  for (i=0; i<numentries-1; i++) {
9179  BigReal A,B,C,D;
9180  currdist = dists[i];
9181 
9182  printf("Interpolating on interval %i\n", i);
9183 
9184  // Set up the coefficients for this section
9185  A = enervalues[i];
9186  B = x[i];
9187  C = 3 * (enervalues[i+1] - enervalues[i]) - (2 * x[i]) - x[i+1];
9188  D = 2 * (enervalues[i] - enervalues[i+1]) + x[i] + x[i+1];
9189 
9190  printf("Coefficients for this interval: %f %f %f %f\n", A, B, C, D);
9191 
9192  // Go over the region of interest and fill in the table
9193  for (j=0; j<entriesperseg; j++) {
9194  const BigReal mydist = currdist + (j * table_spacing);
9195  const BigReal mydistfrac = (float) j / (entriesperseg - 1);
9196  distbin = (int) namdnearbyint(mydist / table_spacing);
9197  if (distbin >= (int) namdnearbyint(maxdist / table_spacing)) break;
9198  BigReal energy;
9199  BigReal force;
9200 
9201  energy = A + (B * mydistfrac) + (C * mydistfrac * mydistfrac) + (D * mydistfrac * mydistfrac * mydistfrac);
9202  force = B + (2 * C * mydistfrac) + (3 * D * mydistfrac * mydistfrac);
9203  // Multiply force by 1 / (interval length)
9204  force *= (1.0 / spacing);
9205 
9206  printf("Adding energy/force entry %f / %f in bins %i / %i for distance %f (%f)\n", energy, force, (table_prefix + 2 * distbin), (table_prefix + 2 * distbin + 1), mydist, mydistfrac);
9207  table_ener[table_prefix + 2 * distbin] = energy;
9208  table_ener[table_prefix + 2 * distbin + 1] = force;
9209  distbin++;
9210  }
9211  if (currdist >= maxdist) break;
9212  }
9213 
9214  //The procedure above leaves out the last entry -- add it explicitly
9215  distbin = (int) namdnearbyint(maxdist / table_spacing);
9216  printf("Adding energy/force entry %f / %f in bins %i / %i\n", enervalues[numentries - 1], 0.0, (table_prefix + 2 * distbin), (table_prefix + 2 * distbin + 1));
9217  table_ener[table_prefix + 2 * distbin] = enervalues[numentries - 1];
9218  table_ener[table_prefix + 2 * distbin + 1] = 0.0;
9219  distbin++;
9220 
9221 
9222  // Clean up and make sure everything worked ok
9223  delete m;
9224  delete x;
9225  delete b;
9226  distbin--;
9227  printf("Testing: %i vs %i (from %f / %f)\n", distbin, (int) (namdnearbyint(maxdist / table_spacing)), maxdist, table_spacing);
9228  if (distbin != (int) (namdnearbyint(maxdist / table_spacing))) return 1;
9229  return 0;
9230 } /* end read_energy_type_cubspline */
#define namdnearbyint(x)
Definition: common.h:85
#define INDEX(ncols, i, j)
Definition: Parameters.C:35
void NAMD_die(const char *err_msg)
Definition: common.C:147
BigReal * table_ener
Definition: Parameters.h:325
double BigReal
Definition: common.h:123

◆ read_parameter_file()

void Parameters::read_parameter_file ( char *  fname)

Definition at line 430 of file Parameters.C.

References Fclose(), Fopen(), NAMD_blank_string(), NAMD_die(), NAMD_find_first_word(), NAMD_read_line(), NumAngleParams, NumBondParams, NumDihedralParams, NumImproperParams, NumTablePairParams, NumVdwPairParams, NumVdwParams, table_ener, and TRUE.

Referenced by Parameters().

432 {
433  char buffer[512]; // Buffer to store each line of the file
434  char first_word[512]; // First word of the current line
435  FILE *pfile; // File descriptor for the parameter file
436 
437  /* Check to make sure that we haven't previously been told */
438  /* that all the files were read */
439  if (AllFilesRead)
440  {
441  NAMD_die("Tried to read another parameter file after being told that all files were read!");
442  }
443 
444  /* Try and open the file */
445  if ( (pfile = Fopen(fname, "r")) == NULL)
446  {
447  char err_msg[512];
448 
449  snprintf(err_msg, sizeof(err_msg),
450  "UNABLE TO OPEN XPLOR PARAMETER FILE %s\n", fname);
451  NAMD_die(err_msg);
452  }
453 
454  /* Keep reading in lines until we hit the EOF */
455  while (NAMD_read_line(pfile, buffer) != -1)
456  {
457  /* Get the first word of the line */
458  NAMD_find_first_word(buffer, first_word);
459 
460  /* First, screen out things that we ignore, such as */
461  /* blank lines, lines that start with '!', lines that */
462  /* start with "REMARK", lines that start with set", */
463  /* and most of the HBOND parameters which include */
464  /* AEXP, REXP, HAEX, AAEX, but not the HBOND statement */
465  /* which is parsed. */
466  if ((buffer[0] != '!') &&
467  !NAMD_blank_string(buffer) &&
468  (strncasecmp(first_word, "REMARK", 6) != 0) &&
469  (strcasecmp(first_word, "set")!=0) &&
470  (strncasecmp(first_word, "AEXP", 4) != 0) &&
471  (strncasecmp(first_word, "REXP", 4) != 0) &&
472  (strncasecmp(first_word, "HAEX", 4) != 0) &&
473  (strncasecmp(first_word, "AAEX", 4) != 0) &&
474  (strncasecmp(first_word, "NBOND", 5) != 0) &&
475  (strncasecmp(first_word, "CUTNB", 5) != 0) &&
476  (strncasecmp(first_word, "END", 3) != 0) &&
477  (strncasecmp(first_word, "CTONN", 5) != 0) &&
478  (strncasecmp(first_word, "EPS", 3) != 0) &&
479  (strncasecmp(first_word, "VSWI", 4) != 0) &&
480  (strncasecmp(first_word, "NBXM", 4) != 0) &&
481  (strncasecmp(first_word, "INHI", 4) != 0) )
482  {
483  /* Now, call the appropriate function based */
484  /* on the type of parameter we have */
485  if (strncasecmp(first_word, "bond", 4)==0)
486  {
487  add_bond_param(buffer, TRUE);
488  NumBondParams++;
489  }
490  else if (strncasecmp(first_word, "angl", 4)==0)
491  {
492  add_angle_param(buffer);
493  NumAngleParams++;
494  }
495  else if (strncasecmp(first_word, "dihe", 4)==0)
496  {
497  add_dihedral_param(buffer, pfile);
499  }
500  else if (strncasecmp(first_word, "impr", 4)==0)
501  {
502  add_improper_param(buffer, pfile);
504  }
505  else if (strncasecmp(first_word, "nonb", 4)==0)
506  {
507  add_vdw_param(buffer);
508  NumVdwParams++;
509  }
510  else if (strncasecmp(first_word, "nbfi", 4)==0)
511  {
512  add_vdw_pair_param(buffer);
513  NumVdwPairParams++;
514  }
515  else if (strncasecmp(first_word, "nbta", 4)==0)
516  {
517 
518  if (table_ener == NULL) {
519  continue;
520  }
521 
522  add_table_pair_param(buffer);
524  }
525  else if (strncasecmp(first_word, "hbon", 4)==0)
526  {
527  add_hb_pair_param(buffer);
528  }
529  else
530  {
531  /* This is an unknown paramter. */
532  /* This is BAD */
533  char err_msg[512];
534 
535  snprintf(err_msg, sizeof(err_msg),
536  "UNKNOWN PARAMETER IN XPLOR PARAMETER FILE %s\nLINE=*%s*",
537  fname, buffer);
538  NAMD_die(err_msg);
539  }
540  }
541  }
542 
543  /* Close the file */
544  Fclose(pfile);
545 
546  return;
547 }
int NumTablePairParams
Definition: Parameters.h:344
int NumBondParams
Definition: Parameters.h:330
int NAMD_read_line(FILE *fd, char *buf, int bufsize)
Definition: strlib.C:38
int NumVdwParams
Definition: Parameters.h:339
int NumVdwPairParams
Definition: Parameters.h:342
void NAMD_find_first_word(char *source, char *word)
Definition: strlib.C:258
int NumAngleParams
Definition: Parameters.h:331
int NumDihedralParams
Definition: Parameters.h:333
int NAMD_blank_string(char *str)
Definition: strlib.C:222
int NumImproperParams
Definition: Parameters.h:334
FILE * Fopen(const char *filename, const char *mode)
Definition: common.C:341
void NAMD_die(const char *err_msg)
Definition: common.C:147
int Fclose(FILE *fout)
Definition: common.C:435
BigReal * table_ener
Definition: Parameters.h:325
#define TRUE
Definition: common.h:128

◆ read_parm() [1/2]

void Parameters::read_parm ( Ambertoppar amber_data,
BigReal  vdw14 
)

Definition at line 7999 of file Parameters.C.

References indexed_vdw_pair::A, indexed_vdw_pair::A14, angle_array, indexed_vdw_pair::B, indexed_vdw_pair::B14, bond_array, Ambertoppar::Cn1, Ambertoppar::Cn2, Ambertoppar::Cno, Ambertoppar::data_read, four_body_consts::delta, dihedral_array, Ambertoppar::HB12, Ambertoppar::HB6, indexed_vdw_pair::ind1, indexed_vdw_pair::ind2, iout, iWARN(), BondValue::k, AngleValue::k, four_body_consts::k, AngleValue::k_ub, indexed_vdw_pair::left, MAX_MULTIPLICITY, DihedralValue::multiplicity, four_body_consts::n, NAMD_die(), AngleValue::normal, Ambertoppar::Nptra, Ambertoppar::Ntypes, Ambertoppar::Numang, NumAngleParams, Ambertoppar::Numbnd, NumBondParams, NumDihedralParams, NumVdwPairParams, NumVdwParamsAssigned, Ambertoppar::Phase, Ambertoppar::Pk, Ambertoppar::Pn, AngleValue::r_ub, Ambertoppar::Req, indexed_vdw_pair::right, Ambertoppar::Rk, Ambertoppar::Teq, AngleValue::theta0, Ambertoppar::Tk, DihedralValue::values, vdw_pair_tree, and BondValue::x0.

8000 {
8001  int i,j,ico,numtype,mul;
8002  IndexedVdwPair *new_node;
8003 
8004  if (!amber_data->data_read)
8005  NAMD_die("No data read from parm file yet!");
8006 
8007  // Copy bond parameters
8008  NumBondParams = amber_data->Numbnd;
8009  if (NumBondParams)
8011  if (bond_array == NULL)
8012  NAMD_die("memory allocation of bond_array failed!");
8013  }
8014  for (i=0; i<NumBondParams; ++i)
8015  { bond_array[i].k = amber_data->Rk[i];
8016  bond_array[i].x0 = amber_data->Req[i];
8017  }
8018 
8019  // Copy angle parameters
8020  NumAngleParams = amber_data->Numang;
8021  if (NumAngleParams)
8023  if (angle_array == NULL)
8024  NAMD_die("memory allocation of angle_array failed!");
8025  }
8026  for (i=0; i<NumAngleParams; ++i)
8027  { angle_array[i].k = amber_data->Tk[i];
8028  angle_array[i].theta0 = amber_data->Teq[i];
8029  // Amber has no k_ub and r_ub for angle parameters, so they're set to 0
8030  angle_array[i].k_ub = angle_array[i].r_ub = 0;
8031  // All angles are harmonic
8032  angle_array[i].normal = 1;
8033  }
8034 
8035  // Copy dihedral parameters
8036  // Note: If the periodicity is negative, it means the following
8037  // entry is another term in a multitermed dihedral, and the
8038  // absolute value is the true periodicity; in this case the
8039  // following entry in "dihedral_array" should be left empty,
8040  // NOT be skipped, in order to keep the next dihedral's index
8041  // unchanged.
8042  NumDihedralParams = amber_data->Nptra;
8043  if (NumDihedralParams)
8044  { dihedral_array = new DihedralValue[amber_data->Nptra];
8045  if (dihedral_array == NULL)
8046  NAMD_die("memory allocation of dihedral_array failed!");
8047  }
8048  mul = 0;
8049  for (i=0; i<NumDihedralParams; ++i)
8050  { dihedral_array[i-mul].values[mul].k = amber_data->Pk[i];
8051  dihedral_array[i-mul].values[mul].n = int(fabs(amber_data->Pn[i])+0.5);
8052  if (dihedral_array[i-mul].values[mul].n == 0) {
8053  char err_msg[512];
8054  snprintf(err_msg, sizeof(err_msg),
8055  "The periodicity of dihedral # %d is zero!", i+1);
8056  NAMD_die(err_msg);
8057  }
8058  dihedral_array[i-mul].values[mul].delta = amber_data->Phase[i];
8059  // If the periodicity is positive, it means the following
8060  // entry is a new dihedral term.
8061  if (amber_data->Pn[i] > 0)
8062  { dihedral_array[i-mul].multiplicity = mul+1;
8063  mul = 0;
8064  }
8065  else if (++mul >= MAX_MULTIPLICITY) {
8066  char err_msg[512];
8067  snprintf(err_msg, sizeof(err_msg),
8068  "Multiple dihedral with multiplicity of %d greater than max of %d",
8069  mul+1, MAX_MULTIPLICITY);
8070  NAMD_die(err_msg);
8071  }
8072  }
8073  if (mul > 0)
8074  NAMD_die("Negative periodicity in the last dihedral entry!");
8075 
8076  // Copy VDW parameters: AMBER explicitly gives VDW parameters between every
8077  // 2 atom types, so the data are copied to vdw_pair_tree
8078  // In AMBER, all 1-4 VDW interactions are divided by factor vdw14
8079  NumVdwParamsAssigned = numtype = amber_data->Ntypes; // Number of atom types
8080  NumVdwPairParams = numtype * (numtype+1) / 2;
8081  for (i=0; i<numtype; ++i)
8082  for (j=i; j<numtype; ++j)
8083  { new_node = new IndexedVdwPair;
8084  if (new_node == NULL)
8085  NAMD_die("memory allocation of vdw_pair_tree failed!");
8086  new_node->ind1 = i;
8087  new_node->ind2 = j;
8088  new_node->left = new_node->right = NULL;
8089  // ico is the index of interaction between atom type i and j into
8090  // the parameter arrays. If it's positive, the interaction is
8091  // 6-12 VDW; otherwise it's 10-12 H-bond interaction. NAMD doesn't
8092  // have 10-12 term, so if ico is negative, then the 10-12
8093  // coefficients must be 0, otherwise die.
8094  ico = amber_data->Cno[numtype*i+j];
8095  if (ico>0)
8096  { new_node->A = amber_data->Cn1[ico-1];
8097  new_node->A14 = new_node->A / vdw14;
8098  new_node->B = amber_data->Cn2[ico-1];
8099  new_node->B14 = new_node->B / vdw14;
8100  }
8101  else if (amber_data->HB12[abs(ico)-1]==0.0 && amber_data->HB6[abs(ico)-1]==0.0)
8102  { new_node->A = new_node->A14 = new_node->B = new_node->B14 = 0.0;
8103  iout << iWARN << "Encounter 10-12 H-bond term\n";
8104  }
8105  else
8106  NAMD_die("Encounter non-zero 10-12 H-bond term!");
8107  // Add the node to the binary tree
8108  vdw_pair_tree = add_to_indexed_vdw_pairs(new_node, vdw_pair_tree);
8109  }
8110 }
int NumBondParams
Definition: Parameters.h:330
_REAL * HB6
Definition: parm.h:24
struct indexed_vdw_pair * right
Definition: Parameters.h:191
_REAL * HB12
Definition: parm.h:24
int NumVdwPairParams
Definition: Parameters.h:342
_REAL * Teq
Definition: parm.h:24
std::ostream & iWARN(std::ostream &s)
Definition: InfoStream.C:82
DihedralValue * dihedral_array
Definition: Parameters.h:314
int Nptra
Definition: parm.h:17
int Ntypes
Definition: parm.h:17
#define iout
Definition: InfoStream.h:51
_REAL * Req
Definition: parm.h:24
int NumAngleParams
Definition: Parameters.h:331
IndexedVdwPair * vdw_pair_tree
Definition: Parameters.h:326
int NumDihedralParams
Definition: Parameters.h:333
FourBodyConsts values[MAX_MULTIPLICITY]
Definition: Parameters.h:128
int * Cno
Definition: parm.h:27
AngleValue * angle_array
Definition: Parameters.h:313
struct indexed_vdw_pair * left
Definition: Parameters.h:192
#define MAX_MULTIPLICITY
Definition: Parameters.h:88
_REAL * Pk
Definition: parm.h:24
_REAL * Cn2
Definition: parm.h:24
struct indexed_vdw_pair IndexedVdwPair
void NAMD_die(const char *err_msg)
Definition: common.C:147
int NumVdwParamsAssigned
Definition: Parameters.h:341
_REAL * Phase
Definition: parm.h:24
_REAL * Tk
Definition: parm.h:24
int Numbnd
Definition: parm.h:17
_REAL * Pn
Definition: parm.h:24
BondValue * bond_array
Definition: Parameters.h:312
_REAL * Rk
Definition: parm.h:24
int data_read
Definition: parm.h:34
Real theta0
Definition: Parameters.h:112
int Numang
Definition: parm.h:17
_REAL * Cn1
Definition: parm.h:24

◆ read_parm() [2/2]

void Parameters::read_parm ( AmberParm7Reader::Ambertoppar amber_data,
BigReal  vdw14 
)

Definition at line 8122 of file Parameters.C.

References indexed_vdw_pair::A, indexed_vdw_pair::A14, angle_array, indexed_vdw_pair::B, indexed_vdw_pair::B14, bond_array, CrosstermValue::c, AmberParm7Reader::Ambertoppar::CMAPParameter, AmberParm7Reader::Ambertoppar::CMAPResolution, AmberParm7Reader::Ambertoppar::CMAPTypeCount, AmberParm7Reader::Ambertoppar::Cn1, AmberParm7Reader::Ambertoppar::Cn2, AmberParm7Reader::Ambertoppar::Cno, crossterm_array, crossterm_setup(), CrosstermData::d00, four_body_consts::delta, dihedral_array, CrosstermValue::dim, AmberParm7Reader::Ambertoppar::HasCMAP, AmberParm7Reader::Ambertoppar::HasData, AmberParm7Reader::Ambertoppar::HB10, AmberParm7Reader::Ambertoppar::HB12, indexed_vdw_pair::ind1, indexed_vdw_pair::ind2, iout, AmberParm7Reader::Ambertoppar::IsCharmmFF, iWARN(), BondValue::k, AngleValue::k, four_body_consts::k, AngleValue::k_ub, indexed_vdw_pair::left, MAX_MULTIPLICITY, DihedralValue::multiplicity, four_body_consts::n, NAMD_die(), AngleValue::normal, AmberParm7Reader::Ambertoppar::Nptra, AmberParm7Reader::Ambertoppar::Ntypes, AmberParm7Reader::Ambertoppar::Numang, NumAngleParams, AmberParm7Reader::Ambertoppar::Numbnd, NumBondParams, NumCrosstermParams, NumDihedralParams, NumVdwPairParams, NumVdwParamsAssigned, AmberParm7Reader::Ambertoppar::Phase, AmberParm7Reader::Ambertoppar::Pk, AmberParm7Reader::Ambertoppar::Pn, AngleValue::r_ub, AmberParm7Reader::Ambertoppar::Req, indexed_vdw_pair::right, AmberParm7Reader::Ambertoppar::Rk, AmberParm7Reader::Ambertoppar::Teq, AngleValue::theta0, AmberParm7Reader::Ambertoppar::Tk, DihedralValue::values, vdw_pair_tree, and BondValue::x0.

8123 {
8124  int i,j,ico,numtype,mul;
8125  IndexedVdwPair *new_node;
8126 
8127  if (!amber_data->HasData) {
8128  NAMD_die("No data read from parm file yet!");
8129  }
8130 
8131  // Check if we are reading a CHARMBER file
8132  if (amber_data->IsCharmmFF) {
8133  NAMD_die("You are using a CHARMM force field in AMBER format generated by CHAMBER or ParmEd.\n"
8134  "We do not support this format. Please consider using the native format (PSF) for CHARMM force field.");
8135  }
8136 
8137  // Copy bond parameters
8138  NumBondParams = amber_data->Numbnd;
8139  if (NumBondParams)
8141  if (bond_array == NULL)
8142  NAMD_die("memory allocation of bond_array failed!");
8143  }
8144  for (i=0; i<NumBondParams; ++i)
8145  { bond_array[i].k = amber_data->Rk[i];
8146  bond_array[i].x0 = amber_data->Req[i];
8147  }
8148 
8149  // Copy angle parameters
8150  NumAngleParams = amber_data->Numang;
8151  if (NumAngleParams)
8153  if (angle_array == NULL)
8154  NAMD_die("memory allocation of angle_array failed!");
8155  }
8156  for (i=0; i<NumAngleParams; ++i)
8157  { angle_array[i].k = amber_data->Tk[i];
8158  angle_array[i].theta0 = amber_data->Teq[i];
8159  // Amber has no k_ub and r_ub for angle parameters, so they're set to 0
8160  angle_array[i].k_ub = angle_array[i].r_ub = 0;
8161  // All angles are harmonic
8162  angle_array[i].normal = 1;
8163  }
8164 
8165  // Copy dihedral parameters
8166  // Note: If the periodicity is negative, it means the following
8167  // entry is another term in a multitermed dihedral, and the
8168  // absolute value is the true periodicity; in this case the
8169  // following entry in "dihedral_array" should be left empty,
8170  // NOT be skipped, in order to keep the next dihedral's index
8171  // unchanged.
8172  NumDihedralParams = amber_data->Nptra;
8173  if (NumDihedralParams)
8174  { dihedral_array = new DihedralValue[amber_data->Nptra];
8175  if (dihedral_array == NULL)
8176  NAMD_die("memory allocation of dihedral_array failed!");
8177  }
8178  mul = 0;
8179  for (i=0; i<NumDihedralParams; ++i)
8180  { dihedral_array[i-mul].values[mul].k = amber_data->Pk[i];
8181  dihedral_array[i-mul].values[mul].n = int(fabs(amber_data->Pn[i])+0.5);
8182  if (dihedral_array[i-mul].values[mul].n == 0) {
8183  char err_msg[512];
8184  snprintf(err_msg, sizeof(err_msg),
8185  "The periodicity of dihedral # %d is zero!", i+1);
8186  NAMD_die(err_msg);
8187  }
8188  dihedral_array[i-mul].values[mul].delta = amber_data->Phase[i];
8189  // If the periodicity is positive, it means the following
8190  // entry is a new dihedral term.
8191  if (amber_data->Pn[i] > 0)
8192  { dihedral_array[i-mul].multiplicity = mul+1;
8193  mul = 0;
8194  }
8195  else if (++mul >= MAX_MULTIPLICITY) {
8196  char err_msg[512];
8197  snprintf(err_msg, sizeof(err_msg),
8198  "Multiple dihedral with multiplicity of %d greater than max of %d",
8199  mul+1, MAX_MULTIPLICITY);
8200  NAMD_die(err_msg);
8201  }
8202  }
8203  if (mul > 0)
8204  NAMD_die("Negative periodicity in the last dihedral entry!");
8205 
8206  // Copy crossterms
8207  if (amber_data->HasCMAP) {
8208  NumCrosstermParams = amber_data->CMAPTypeCount;
8209  if (NumCrosstermParams > 0) {
8211  for (i = 0; i < NumCrosstermParams; ++i) {
8212  // check the resolutions at first
8213  const int N = amber_data->CMAPResolution[i];
8214  // NAMD does not support a resolution number other than CrosstermValue::dim - 1
8215  if (N != CrosstermValue::dim - 1) {
8216  char err_msg[512];
8217  snprintf(err_msg, sizeof(err_msg),
8218  "The table of %d crossterm type has a resolution(%d) "
8219  "other than %d!",
8220  i+1, N, CrosstermValue::dim - 1);
8221  NAMD_die(err_msg);
8222  }
8223  // code swipe from Parameters::index_crossterms()
8224  int l = 0;
8225  for (int j = 0; j < N; ++j) {
8226  for (int k = 0; k < N; ++k) {
8227  crossterm_array[i].c[j][k].d00 = amber_data->CMAPParameter[i][l];
8228  ++l;
8229  }
8230  }
8231  for (int j = 0; j < N; ++j) {
8232  crossterm_array[i].c[j][N].d00 = crossterm_array[i].c[j][0].d00;
8233  crossterm_array[i].c[N][j].d00 = crossterm_array[i].c[0][j].d00;
8234  }
8235  crossterm_array[i].c[N][N] = crossterm_array[i].c[0][0];
8236  crossterm_setup(&crossterm_array[i].c[0][0]);
8237  }
8238  }
8239  }
8240 
8241  // Copy VDW parameters: AMBER explicitly gives VDW parameters between every
8242  // 2 atom types, so the data are copied to vdw_pair_tree
8243  // In AMBER, all 1-4 VDW interactions are divided by factor vdw14
8244  NumVdwParamsAssigned = numtype = amber_data->Ntypes; // Number of atom types
8245  NumVdwPairParams = numtype * (numtype+1) / 2;
8246  for (i=0; i<numtype; ++i)
8247  for (j=i; j<numtype; ++j)
8248  { new_node = new IndexedVdwPair;
8249  if (new_node == NULL)
8250  NAMD_die("memory allocation of vdw_pair_tree failed!");
8251  new_node->ind1 = i;
8252  new_node->ind2 = j;
8253  new_node->left = new_node->right = NULL;
8254  // ico is the index of interaction between atom type i and j into
8255  // the parameter arrays. If it's positive, the interaction is
8256  // 6-12 VDW; otherwise it's 10-12 H-bond interaction. NAMD doesn't
8257  // have 10-12 term, so if ico is negative, then the 10-12
8258  // coefficients must be 0, otherwise die.
8259  ico = amber_data->Cno[numtype*i+j];
8260  if (ico>0)
8261  { new_node->A = amber_data->Cn1[ico-1];
8262  new_node->A14 = new_node->A / vdw14;
8263  new_node->B = amber_data->Cn2[ico-1];
8264  new_node->B14 = new_node->B / vdw14;
8265  }
8266  else if (amber_data->HB12[abs(ico)-1]==0.0 && amber_data->HB10[abs(ico)-1]==0.0)
8267  { new_node->A = new_node->A14 = new_node->B = new_node->B14 = 0.0;
8268  iout << iWARN << "Encounter 10-12 H-bond term\n";
8269  }
8270  else
8271  NAMD_die("Encounter non-zero 10-12 H-bond term!");
8272  // Add the node to the binary tree
8273  vdw_pair_tree = add_to_indexed_vdw_pairs(new_node, vdw_pair_tree);
8274  }
8275 }
int NumBondParams
Definition: Parameters.h:330
CrosstermData c[dim][dim]
Definition: Parameters.h:145
struct indexed_vdw_pair * right
Definition: Parameters.h:191
int NumVdwPairParams
Definition: Parameters.h:342
void crossterm_setup(CrosstermData *)
std::ostream & iWARN(std::ostream &s)
Definition: InfoStream.C:82
DihedralValue * dihedral_array
Definition: Parameters.h:314
#define iout
Definition: InfoStream.h:51
int NumAngleParams
Definition: Parameters.h:331
CrosstermValue * crossterm_array
Definition: Parameters.h:316
IndexedVdwPair * vdw_pair_tree
Definition: Parameters.h:326
int NumDihedralParams
Definition: Parameters.h:333
FourBodyConsts values[MAX_MULTIPLICITY]
Definition: Parameters.h:128
AngleValue * angle_array
Definition: Parameters.h:313
struct indexed_vdw_pair * left
Definition: Parameters.h:192
#define MAX_MULTIPLICITY
Definition: Parameters.h:88
BigReal d00
Definition: Parameters.h:137
struct indexed_vdw_pair IndexedVdwPair
int NumCrosstermParams
Definition: Parameters.h:335
void NAMD_die(const char *err_msg)
Definition: common.C:147
int NumVdwParamsAssigned
Definition: Parameters.h:341
vector< vector< _REAL > > CMAPParameter
BondValue * bond_array
Definition: Parameters.h:312
Real theta0
Definition: Parameters.h:112

◆ receive_Parameters()

void Parameters::receive_Parameters ( MIStream msg)

Definition at line 6936 of file Parameters.C.

References indexed_vdw_pair::A, indexed_vdw_pair::A14, nbthole_pair_value::alphai, nbthole_pair_value::alphaj, angle_array, indexed_vdw_pair::B, indexed_vdw_pair::B14, bond_array, crossterm_array, four_body_consts::delta, dihedral_array, CrosstermValue::dim, vdw_val::epsilon, vdw_val::epsilon14, MIStream::get(), gromacsPair_array, improper_array, indexed_vdw_pair::ind1, nbthole_pair_value::ind1, indexed_table_pair::ind1, indexed_vdw_pair::ind2, nbthole_pair_value::ind2, indexed_table_pair::ind2, BondValue::k, AngleValue::k, four_body_consts::k, indexed_table_pair::K, AngleValue::k_ub, indexed_vdw_pair::left, MAX_ATOMTYPE_CHARS, MAX_MULTIPLICITY, DihedralValue::multiplicity, ImproperValue::multiplicity, four_body_consts::n, NAMD_die(), nbthole_array, AngleValue::normal, NumAngleParams, NumBondParams, NumCrosstermParams, NumDihedralParams, numenerentries, NumGromacsPairParams, NumImproperParams, NumNbtholePairParams, NumTablePairParams, NumVdwPairParams, NumVdwParams, NumVdwParamsAssigned, GromacsPairValue::pairC12, GromacsPairValue::pairC6, AngleValue::r_ub, indexed_vdw_pair::right, vdw_val::sigma, vdw_val::sigma14, tab_pair_tree, table_ener, AngleValue::theta0, nbthole_pair_value::tholeij, TRUE, DihedralValue::values, ImproperValue::values, vdw_array, vdw_pair_tree, and BondValue::x0.

Referenced by Node::resendMolecule().

6938 {
6939  int i, j; // Loop counters
6940  Real *a1, *a2, *a3, *a4; // Temporary arrays to get data from message in
6941  int *i1, *i2, *i3; // Temporary int array to get data from message in
6942  IndexedVdwPair *new_node; // New node for vdw pair param tree
6943  IndexedTablePair *new_tab_node;
6944  Real **kvals; // Force constant values for dihedrals and impropers
6945  int **nvals; // Periodicity values for dihedrals and impropers
6946  Real **deltavals; // Phase shift values for dihedrals and impropers
6947  BigReal *pairC6, *pairC12; // JLai
6948 
6949  // Get the bonded parameters
6950  msg->get(NumBondParams);
6951 
6952  if (NumBondParams)
6953  {
6955  a1 = new Real[NumBondParams];
6956  a2 = new Real[NumBondParams];
6957 
6958  if ( (bond_array == NULL) || (a1 == NULL) || (a2 == NULL) )
6959  {
6960  NAMD_die("memory allocation failed in Parameters::receive_Parameters");
6961  }
6962 
6963  msg->get(NumBondParams, a1);
6964  msg->get(NumBondParams, a2);
6965 
6966  for (i=0; i<NumBondParams; i++)
6967  {
6968  bond_array[i].k = a1[i];
6969  bond_array[i].x0 = a2[i];
6970  }
6971 
6972  delete [] a1;
6973  delete [] a2;
6974  }
6975 
6976  // Get the angle parameters
6977  msg->get(NumAngleParams);
6978 
6979  if (NumAngleParams)
6980  {
6982  a1 = new Real[NumAngleParams];
6983  a2 = new Real[NumAngleParams];
6984  a3 = new Real[NumAngleParams];
6985  a4 = new Real[NumAngleParams];
6986  i1 = new int[NumAngleParams];
6987 
6988  if ( (angle_array == NULL) || (a1 == NULL) || (a2 == NULL) ||
6989  (a3 == NULL) || (a4 == NULL) || (i1 == NULL))
6990  {
6991  NAMD_die("memory allocation failed in Parameters::receive_Parameters");
6992  }
6993 
6994  msg->get(NumAngleParams, a1);
6995  msg->get(NumAngleParams, a2);
6996  msg->get(NumAngleParams, a3);
6997  msg->get(NumAngleParams, a4);
6998  msg->get(NumAngleParams, i1);
6999 
7000  for (i=0; i<NumAngleParams; i++)
7001  {
7002  angle_array[i].k = a1[i];
7003  angle_array[i].theta0 = a2[i];
7004  angle_array[i].k_ub = a3[i];
7005  angle_array[i].r_ub = a4[i];
7006  angle_array[i].normal = i1[i];
7007  }
7008 
7009  delete [] a1;
7010  delete [] a2;
7011  delete [] a3;
7012  delete [] a4;
7013  delete [] i1;
7014  }
7015 
7016  // Get the dihedral parameters
7017  msg->get(NumDihedralParams);
7018 
7019  if (NumDihedralParams)
7020  {
7022 
7023  i1 = new int[NumDihedralParams];
7024  kvals = new Real *[MAX_MULTIPLICITY];
7025  nvals = new int *[MAX_MULTIPLICITY];
7026  deltavals = new Real *[MAX_MULTIPLICITY];
7027 
7028  if ( (i1 == NULL) || (kvals == NULL) || (nvals == NULL) ||
7029  (deltavals == NULL) || (dihedral_array == NULL) )
7030  {
7031  NAMD_die("memory allocation failed in Parameters::send_Parameters");
7032  }
7033 
7034  for (i=0; i<MAX_MULTIPLICITY; i++)
7035  {
7036  kvals[i] = new Real[NumDihedralParams];
7037  nvals[i] = new int[NumDihedralParams];
7038  deltavals[i] = new Real[NumDihedralParams];
7039 
7040  if ( (kvals[i] == NULL) || (nvals[i] == NULL) || (deltavals[i] == NULL) )
7041  {
7042  NAMD_die("memory allocation failed in Parameters::send_Parameters");
7043  }
7044  }
7045 
7046  msg->get(NumDihedralParams, i1);
7047 
7048  for (i=0; i<MAX_MULTIPLICITY; i++)
7049  {
7050  msg->get(NumDihedralParams, kvals[i]);
7051  msg->get(NumDihedralParams, nvals[i]);
7052  msg->get(NumDihedralParams, deltavals[i]);
7053  }
7054 
7055  for (i=0; i<NumDihedralParams; i++)
7056  {
7057  dihedral_array[i].multiplicity = i1[i];
7058 
7059  for (j=0; j<MAX_MULTIPLICITY; j++)
7060  {
7061  dihedral_array[i].values[j].k = kvals[j][i];
7062  dihedral_array[i].values[j].n = nvals[j][i];
7063  dihedral_array[i].values[j].delta = deltavals[j][i];
7064  }
7065  }
7066 
7067  for (i=0; i<MAX_MULTIPLICITY; i++)
7068  {
7069  delete [] kvals[i];
7070  delete [] nvals[i];
7071  delete [] deltavals[i];
7072  }
7073 
7074  delete [] i1;
7075  delete [] kvals;
7076  delete [] nvals;
7077  delete [] deltavals;
7078  }
7079 
7080  // Get the improper parameters
7081  msg->get(NumImproperParams);
7082 
7083  if (NumImproperParams)
7084  {
7086  i1 = new int[NumImproperParams];
7087  kvals = new Real *[MAX_MULTIPLICITY];
7088  nvals = new int *[MAX_MULTIPLICITY];
7089  deltavals = new Real *[MAX_MULTIPLICITY];
7090 
7091  if ( (i1 == NULL) || (kvals == NULL) || (nvals == NULL) ||
7092  (deltavals == NULL) || (improper_array==NULL) )
7093  {
7094  NAMD_die("memory allocation failed in Parameters::send_Parameters");
7095  }
7096 
7097  for (i=0; i<MAX_MULTIPLICITY; i++)
7098  {
7099  kvals[i] = new Real[NumImproperParams];
7100  nvals[i] = new int[NumImproperParams];
7101  deltavals[i] = new Real[NumImproperParams];
7102 
7103  if ( (kvals[i] == NULL) || (nvals[i] == NULL) || (deltavals[i] == NULL) )
7104  {
7105  NAMD_die("memory allocation failed in Parameters::send_Parameters");
7106  }
7107  }
7108 
7109  msg->get(NumImproperParams,i1);
7110 
7111  for (i=0; i<MAX_MULTIPLICITY; i++)
7112  {
7113  msg->get(NumImproperParams,kvals[i]);
7114  msg->get(NumImproperParams,nvals[i]);
7115  msg->get(NumImproperParams,deltavals[i]);
7116  }
7117 
7118  for (i=0; i<NumImproperParams; i++)
7119  {
7120  improper_array[i].multiplicity = i1[i];
7121 
7122  for (j=0; j<MAX_MULTIPLICITY; j++)
7123  {
7124  improper_array[i].values[j].k = kvals[j][i];
7125  improper_array[i].values[j].n = nvals[j][i];
7126  improper_array[i].values[j].delta = deltavals[j][i];
7127  }
7128  }
7129 
7130  for (i=0; i<MAX_MULTIPLICITY; i++)
7131  {
7132  delete [] kvals[i];
7133  delete [] nvals[i];
7134  delete [] deltavals[i];
7135  }
7136 
7137  delete [] i1;
7138  delete [] kvals;
7139  delete [] nvals;
7140  delete [] deltavals;
7141  }
7142 
7143  // Get the crossterm parameters
7144  msg->get(NumCrosstermParams);
7145 
7146  if (NumCrosstermParams)
7147  {
7149 
7150  for (i=0; i<NumCrosstermParams; ++i) {
7151  int nvals = CrosstermValue::dim * CrosstermValue::dim * 2 * 2;
7152  msg->get(nvals,&crossterm_array[i].c[0][0].d00);
7153  }
7154  }
7155 
7156  // Get GromacsPairs parameters
7157  // JLai
7158  msg->get(NumGromacsPairParams);
7159 
7161  {
7163  pairC6 = new BigReal[NumGromacsPairParams];
7164  pairC12 = new BigReal[NumGromacsPairParams];
7165 
7166  if ( (pairC6 == NULL) || (pairC12 == NULL) ) {
7167  NAMD_die("memory allocation failed in Parameters::receive_Parameters");
7168  }
7169 
7170  msg->get(NumGromacsPairParams,pairC6);
7171  msg->get(NumGromacsPairParams,pairC12);
7172 
7173  for (i=0; i<NumGromacsPairParams; ++i) {
7174  gromacsPair_array[i].pairC6 = pairC6[i];
7175  gromacsPair_array[i].pairC12 = pairC12[i];
7176  }
7177 
7178  delete [] pairC6;
7179  delete [] pairC12;
7180  }
7181  // JLai
7182 
7183  //Get the energy table
7184  msg->get(numenerentries);
7185  if (numenerentries > 0) {
7186  //fprintf(stdout, "Getting tables\n");
7187  //fprintf(infofile, "Trying to allocate table\n");
7189  //fprintf(infofile, "Finished table allocation\n");
7190  if (table_ener==NULL)
7191  {
7192  NAMD_die("memory allocation failed in Parameters::receive_Parameters");
7193  }
7194 
7195  msg->get(numenerentries, table_ener);
7196  }
7197 
7198  // Get the vdw parameters
7199  msg->get(NumVdwParams);
7200  msg->get(NumVdwParamsAssigned);
7201 
7202  if (NumVdwParams)
7203  {
7204  atomTypeNames = new char[NumVdwParams*(MAX_ATOMTYPE_CHARS+1)];
7206  a1 = new Real[NumVdwParams];
7207  a2 = new Real[NumVdwParams];
7208  a3 = new Real[NumVdwParams];
7209  a4 = new Real[NumVdwParams];
7210 
7211  if ( (vdw_array==NULL) || (a1==NULL) || (a2==NULL) || (a3==NULL)
7212  || (a4==NULL) || (atomTypeNames==NULL))
7213  {
7214  NAMD_die("memory allocation failed in Parameters::receive_Parameters");
7215  }
7216 
7217  msg->get(NumVdwParams * (MAX_ATOMTYPE_CHARS+1), atomTypeNames);
7218  msg->get(NumVdwParams, a1);
7219  msg->get(NumVdwParams, a2);
7220  msg->get(NumVdwParams, a3);
7221  msg->get(NumVdwParams, a4);
7222 
7223  for (i=0; i<NumVdwParams; i++)
7224  {
7225  vdw_array[i].sigma = a1[i];
7226  vdw_array[i].epsilon = a2[i];
7227  vdw_array[i].sigma14 = a3[i];
7228  vdw_array[i].epsilon14 = a4[i];
7229  }
7230 
7231  delete [] a1;
7232  delete [] a2;
7233  delete [] a3;
7234  delete [] a4;
7235  }
7236 
7237  // Get the vdw_pair_parameters
7238  msg->get(NumVdwPairParams);
7239 
7240  if (NumVdwPairParams)
7241  {
7242  a1 = new Real[NumVdwPairParams];
7243  a2 = new Real[NumVdwPairParams];
7244  a3 = new Real[NumVdwPairParams];
7245  a4 = new Real[NumVdwPairParams];
7246  i1 = new int[NumVdwPairParams];
7247  i2 = new int[NumVdwPairParams];
7248 
7249  if ( (a1 == NULL) || (a2 == NULL) || (a3 == NULL) || (a4 == NULL) ||
7250  (i1 == NULL) || (i2 == NULL) )
7251  {
7252  NAMD_die("memory allocation failed in Parameters::send_Parameters");
7253  }
7254 
7255  msg->get(NumVdwPairParams, i1);
7256  msg->get(NumVdwPairParams, i2);
7257  msg->get(NumVdwPairParams, a1);
7258  msg->get(NumVdwPairParams, a2);
7259  msg->get(NumVdwPairParams, a3);
7260  msg->get(NumVdwPairParams, a4);
7261 
7262  for (i=0; i<NumVdwPairParams; i++)
7263  {
7264  new_node = (IndexedVdwPair *) malloc(sizeof(IndexedVdwPair));
7265 
7266  if (new_node == NULL)
7267  {
7268  NAMD_die("memory allocation failed in Parameters::receive_Parameters");
7269  }
7270 
7271  new_node->ind1 = i1[i];
7272  new_node->ind2 = i2[i];
7273  new_node->A = a1[i];
7274  new_node->A14 = a2[i];
7275  new_node->B = a3[i];
7276  new_node->B14 = a4[i];
7277  new_node->left = NULL;
7278  new_node->right = NULL;
7279 
7280  vdw_pair_tree = add_to_indexed_vdw_pairs(new_node, vdw_pair_tree);
7281  }
7282 
7283  delete [] i1;
7284  delete [] i2;
7285  delete [] a1;
7286  delete [] a2;
7287  delete [] a3;
7288  delete [] a4;
7289  }
7290 
7291  // Get the nbthole_pair_parameters
7292  msg->get(NumNbtholePairParams);
7293 
7295  {
7297  a1 = new Real[NumNbtholePairParams];
7298  a2 = new Real[NumNbtholePairParams];
7299  a3 = new Real[NumNbtholePairParams];
7300  i1 = new int[NumNbtholePairParams];
7301  i2 = new int[NumNbtholePairParams];
7302 
7303  if ( (nbthole_array == NULL) || (a1 == NULL) || (a2 == NULL) || (a3 == NULL)
7304  || (i1 == NULL) || (i2 == NULL) )
7305  {
7306  NAMD_die("memory allocation failed in Parameters::receive_Parameters");
7307  }
7308 
7309  msg->get(NumNbtholePairParams, i1);
7310  msg->get(NumNbtholePairParams, i2);
7311  msg->get(NumNbtholePairParams, a1);
7312  msg->get(NumNbtholePairParams, a2);
7313  msg->get(NumNbtholePairParams, a3);
7314 
7315  for (i=0; i<NumNbtholePairParams; i++)
7316  {
7317 
7318  nbthole_array[i].ind1 = i1[i];
7319  nbthole_array[i].ind2 = i2[i];
7320  nbthole_array[i].alphai = a1[i];
7321  nbthole_array[i].alphaj = a2[i];
7322  nbthole_array[i].tholeij = a3[i];
7323 
7324  }
7325 
7326  delete [] i1;
7327  delete [] i2;
7328  delete [] a1;
7329  delete [] a2;
7330  delete [] a3;
7331  }
7332 
7333  // Get the table_pair_parameters
7334  msg->get(NumTablePairParams);
7335 
7336  if (NumTablePairParams)
7337  {
7338  i1 = new int[NumTablePairParams];
7339  i2 = new int[NumTablePairParams];
7340  i3 = new int[NumTablePairParams];
7341 
7342  if ( (i3 == NULL) || (i1 == NULL) || (i2 == NULL) )
7343  {
7344  NAMD_die("memory allocation failed in Parameters::send_Parameters");
7345  }
7346 
7347  msg->get(NumTablePairParams, i1);
7348  msg->get(NumTablePairParams, i2);
7349  msg->get(NumTablePairParams, i3);
7350 
7351  for (i=0; i<NumTablePairParams; i++)
7352  {
7353  new_tab_node = (IndexedTablePair *) malloc(sizeof(IndexedTablePair));
7354 
7355  if (new_tab_node == NULL)
7356  {
7357  NAMD_die("memory allocation failed in Parameters::receive_Parameters");
7358  }
7359 
7360 // printf("Adding new table pair with ind1 %i ind2 %i k %i\n", i1[i], i2[i],i3[i]);
7361  new_tab_node->ind1 = i1[i];
7362  new_tab_node->ind2 = i2[i];
7363  new_tab_node->K = i3[i];
7364 #ifndef ACCELERATED_INPUT_TABLE_PAIR
7365  new_tab_node->left = NULL;
7366  new_tab_node->right = NULL;
7367 #endif
7368  tab_pair_tree = add_to_indexed_table_pairs(new_tab_node, tab_pair_tree);
7369  }
7370 
7371  delete [] i1;
7372  delete [] i2;
7373  delete [] i3;
7374  }
7375 
7376  // receive the hydrogen bond parameters
7377  // hbondParams.receive_message(msg);
7378 
7379  AllFilesRead = TRUE;
7380 
7381  delete msg;
7382 }
int numenerentries
Definition: Parameters.h:322
int NumTablePairParams
Definition: Parameters.h:344
GromacsPairValue * gromacsPair_array
Definition: Parameters.h:318
int NumBondParams
Definition: Parameters.h:330
Real epsilon
Definition: Parameters.h:174
struct indexed_vdw_pair * right
Definition: Parameters.h:191
int NumVdwParams
Definition: Parameters.h:339
float Real
Definition: common.h:118
int NumVdwPairParams
Definition: Parameters.h:342
Real sigma14
Definition: Parameters.h:175
MIStream * get(char &data)
Definition: MStream.h:29
DihedralValue * dihedral_array
Definition: Parameters.h:314
int NumAngleParams
Definition: Parameters.h:331
CrosstermValue * crossterm_array
Definition: Parameters.h:316
IndexedVdwPair * vdw_pair_tree
Definition: Parameters.h:326
int NumDihedralParams
Definition: Parameters.h:333
FourBodyConsts values[MAX_MULTIPLICITY]
Definition: Parameters.h:128
AngleValue * angle_array
Definition: Parameters.h:313
struct indexed_vdw_pair * left
Definition: Parameters.h:192
int NumNbtholePairParams
Definition: Parameters.h:343
#define MAX_MULTIPLICITY
Definition: Parameters.h:88
Real sigma
Definition: Parameters.h:173
int NumImproperParams
Definition: Parameters.h:334
int NumCrosstermParams
Definition: Parameters.h:335
ImproperValue * improper_array
Definition: Parameters.h:315
void NAMD_die(const char *err_msg)
Definition: common.C:147
int NumVdwParamsAssigned
Definition: Parameters.h:341
NbtholePairValue * nbthole_array
Definition: Parameters.h:321
FourBodyConsts values[MAX_MULTIPLICITY]
Definition: Parameters.h:134
VdwValue * vdw_array
Definition: Parameters.h:320
BigReal * table_ener
Definition: Parameters.h:325
BondValue * bond_array
Definition: Parameters.h:312
int NumGromacsPairParams
Definition: Parameters.h:337
Real epsilon14
Definition: Parameters.h:176
Real theta0
Definition: Parameters.h:112
IndexedTablePair * tab_pair_tree
Definition: Parameters.h:328
#define TRUE
Definition: common.h:128
#define MAX_ATOMTYPE_CHARS
Definition: Parameters.h:91
double BigReal
Definition: common.h:123

◆ send_Parameters()

void Parameters::send_Parameters ( MOStream msg)

Definition at line 6560 of file Parameters.C.

References nbthole_pair_value::alphai, nbthole_pair_value::alphaj, angle_array, bond_array, crossterm_array, four_body_consts::delta, dihedral_array, CrosstermValue::dim, MOStream::end(), vdw_val::epsilon, vdw_val::epsilon14, gromacsPair_array, improper_array, nbthole_pair_value::ind1, nbthole_pair_value::ind2, BondValue::k, AngleValue::k, four_body_consts::k, AngleValue::k_ub, MAX_ATOMTYPE_CHARS, MAX_MULTIPLICITY, DihedralValue::multiplicity, ImproperValue::multiplicity, four_body_consts::n, NAMD_die(), nbthole_array, nbthole_pair_tree, AngleValue::normal, NumAngleParams, NumBondParams, NumCrosstermParams, NumDihedralParams, numenerentries, NumGromacsPairParams, NumImproperParams, NumNbtholePairParams, NumTablePairParams, NumVdwPairParams, NumVdwParams, NumVdwParamsAssigned, GromacsPairValue::pairC12, GromacsPairValue::pairC6, MOStream::put(), AngleValue::r_ub, vdw_val::sigma, vdw_val::sigma14, tab_pair_tree, table_ener, AngleValue::theta0, nbthole_pair_value::tholeij, DihedralValue::values, ImproperValue::values, vdw_array, vdw_pair_tree, and BondValue::x0.

Referenced by Node::resendMolecule().

6561 {
6562  Real *a1, *a2, *a3, *a4; // Temporary arrays for sending messages
6563  int *i1, *i2, *i3; // Temporary int array
6564  int i, j; // Loop counters
6565  Real **kvals; // Force constant values for dihedrals and impropers
6566  int **nvals; // Periodicity values for dihedrals and impropers
6567  Real **deltavals; // Phase shift values for dihedrals and impropers
6568  BigReal *pairC6, *pairC12; // JLai
6569  /*MOStream *msg=comm_obj->newOutputStream(ALLBUTME, STATICPARAMSTAG, BUFSIZE);
6570  if ( msg == NULL )
6571  {
6572  NAMD_die("memory allocation failed in Parameters::send_Parameters");
6573  }*/
6574 
6575  // Send the bond parameters
6576  msg->put(NumBondParams);
6577 
6578  if (NumBondParams)
6579  {
6580  a1 = new Real[NumBondParams];
6581  a2 = new Real[NumBondParams];
6582 
6583  if ( (a1 == NULL) || (a2 == NULL) )
6584  {
6585  NAMD_die("memory allocation failed in Parameters::send_Parameters");
6586  }
6587 
6588  for (i=0; i<NumBondParams; i++)
6589  {
6590  a1[i] = bond_array[i].k;
6591  a2[i] = bond_array[i].x0;
6592  }
6593 
6594  msg->put(NumBondParams, a1)->put(NumBondParams, a2);
6595 
6596  delete [] a1;
6597  delete [] a2;
6598  }
6599 
6600  // Send the angle parameters
6601  msg->put(NumAngleParams);
6602 
6603  if (NumAngleParams)
6604  {
6605  a1 = new Real[NumAngleParams];
6606  a2 = new Real[NumAngleParams];
6607  a3 = new Real[NumAngleParams];
6608  a4 = new Real[NumAngleParams];
6609  i1 = new int[NumAngleParams];
6610 
6611  if ( (a1 == NULL) || (a2 == NULL) || (a3 == NULL) ||
6612  (a4 == NULL) || (i1 == NULL))
6613  {
6614  NAMD_die("memory allocation failed in Parameters::send_Parameters");
6615  }
6616 
6617  for (i=0; i<NumAngleParams; i++)
6618  {
6619  a1[i] = angle_array[i].k;
6620  a2[i] = angle_array[i].theta0;
6621  a3[i] = angle_array[i].k_ub;
6622  a4[i] = angle_array[i].r_ub;
6623  i1[i] = angle_array[i].normal;
6624  }
6625 
6626  msg->put(NumAngleParams, a1)->put(NumAngleParams, a2);
6627  msg->put(NumAngleParams, a3)->put(NumAngleParams, a4);
6628  msg->put(NumAngleParams, i1);
6629 
6630  delete [] a1;
6631  delete [] a2;
6632  delete [] a3;
6633  delete [] a4;
6634  delete [] i1;
6635  }
6636 
6637  // Send the dihedral parameters
6638  msg->put(NumDihedralParams);
6639 
6640  if (NumDihedralParams)
6641  {
6642  i1 = new int[NumDihedralParams];
6643  kvals = new Real *[MAX_MULTIPLICITY];
6644  nvals = new int *[MAX_MULTIPLICITY];
6645  deltavals = new Real *[MAX_MULTIPLICITY];
6646 
6647  if ( (i1 == NULL) || (kvals == NULL) || (nvals == NULL) ||
6648  (deltavals == NULL) )
6649  {
6650  NAMD_die("memory allocation failed in Parameters::send_Parameters");
6651  }
6652 
6653  for (i=0; i<MAX_MULTIPLICITY; i++)
6654  {
6655  kvals[i] = new Real[NumDihedralParams];
6656  nvals[i] = new int[NumDihedralParams];
6657  deltavals[i] = new Real[NumDihedralParams];
6658 
6659  if ( (kvals[i] == NULL) || (nvals[i] == NULL) || (deltavals[i] == NULL) )
6660  {
6661  NAMD_die("memory allocation failed in Parameters::send_Parameters");
6662  }
6663  }
6664 
6665  for (i=0; i<NumDihedralParams; i++)
6666  {
6667  i1[i] = dihedral_array[i].multiplicity;
6668 
6669  for (j=0; j<MAX_MULTIPLICITY; j++)
6670  {
6671  kvals[j][i] = dihedral_array[i].values[j].k;
6672  nvals[j][i] = dihedral_array[i].values[j].n;
6673  deltavals[j][i] = dihedral_array[i].values[j].delta;
6674  }
6675  }
6676 
6677  msg->put(NumDihedralParams, i1);
6678 
6679  for (i=0; i<MAX_MULTIPLICITY; i++)
6680  {
6681  msg->put(NumDihedralParams, kvals[i]);
6682  msg->put(NumDihedralParams, nvals[i]);
6683  msg->put(NumDihedralParams, deltavals[i]);
6684 
6685  delete [] kvals[i];
6686  delete [] nvals[i];
6687  delete [] deltavals[i];
6688  }
6689 
6690  delete [] i1;
6691  delete [] kvals;
6692  delete [] nvals;
6693  delete [] deltavals;
6694  }
6695 
6696  // Send the improper parameters
6697  msg->put(NumImproperParams);
6698 
6699  if (NumImproperParams)
6700  {
6701  i1 = new int[NumImproperParams];
6702  kvals = new Real *[MAX_MULTIPLICITY];
6703  nvals = new int *[MAX_MULTIPLICITY];
6704  deltavals = new Real *[MAX_MULTIPLICITY];
6705 
6706  if ( (i1 == NULL) || (kvals == NULL) || (nvals == NULL) ||
6707  (deltavals == NULL) )
6708  {
6709  NAMD_die("memory allocation failed in Parameters::send_Parameters");
6710  }
6711 
6712  for (i=0; i<MAX_MULTIPLICITY; i++)
6713  {
6714  kvals[i] = new Real[NumImproperParams];
6715  nvals[i] = new int[NumImproperParams];
6716  deltavals[i] = new Real[NumImproperParams];
6717 
6718  if ( (kvals[i] == NULL) || (nvals[i] == NULL) || (deltavals[i] == NULL) )
6719  {
6720  NAMD_die("memory allocation failed in Parameters::send_Parameters");
6721  }
6722  }
6723 
6724  for (i=0; i<NumImproperParams; i++)
6725  {
6726  i1[i] = improper_array[i].multiplicity;
6727 
6728  for (j=0; j<MAX_MULTIPLICITY; j++)
6729  {
6730  kvals[j][i] = improper_array[i].values[j].k;
6731  nvals[j][i] = improper_array[i].values[j].n;
6732  deltavals[j][i] = improper_array[i].values[j].delta;
6733  }
6734  }
6735 
6736  msg->put(NumImproperParams, i1);
6737 
6738  for (i=0; i<MAX_MULTIPLICITY; i++)
6739  {
6740  msg->put(NumImproperParams, kvals[i]);
6741  msg->put(NumImproperParams, nvals[i]);
6742  msg->put(NumImproperParams, deltavals[i]);
6743 
6744  delete [] kvals[i];
6745  delete [] nvals[i];
6746  delete [] deltavals[i];
6747  }
6748 
6749  delete [] i1;
6750  delete [] kvals;
6751  delete [] nvals;
6752  delete [] deltavals;
6753  }
6754 
6755  // Send the crossterm parameters
6756  msg->put(NumCrosstermParams);
6757 
6758  if (NumCrosstermParams)
6759  {
6760  for (i=0; i<NumCrosstermParams; ++i) {
6761  int nvals = CrosstermValue::dim * CrosstermValue::dim * 2 * 2;
6762  msg->put(nvals,&crossterm_array[i].c[0][0].d00);
6763  }
6764  }
6765  // Send the GromacsPairs parameters
6766  // JLai
6767  msg->put(NumGromacsPairParams);
6768 
6770  {
6771  pairC6 = new BigReal[NumGromacsPairParams];
6772  pairC12 = new BigReal[NumGromacsPairParams];
6773  if ( (pairC6 == NULL) || (pairC12 == NULL) ) {
6774  NAMD_die("memory allocation failed in Parameters::send_Parameters");
6775  }
6776 
6777  for (i=0; i<NumGromacsPairParams; i++) {
6778  pairC6[i] = gromacsPair_array[i].pairC6;
6779  pairC12[i] = gromacsPair_array[i].pairC12;
6780  }
6781 
6782  msg->put(NumGromacsPairParams,pairC6);
6783  msg->put(NumGromacsPairParams,pairC12);
6784 
6785  delete [] pairC6;
6786  delete [] pairC12;
6787  }
6788  // End of JLai
6789 
6790  //
6791  //Send the energy table parameters
6792  msg->put(numenerentries);
6793 
6794  if (numenerentries) {
6795  /*
6796  b1 = new Real[numenerentries];
6797  if (b1 == NULL)
6798  {
6799  NAMD_die("memory allocation failed in Parameters::send_Parameters");
6800  }
6801  */
6802 
6803  msg->put(numenerentries, table_ener);
6804  }
6805 
6806  // Send the vdw parameters
6807  msg->put(NumVdwParams);
6808  msg->put(NumVdwParamsAssigned);
6809 
6810  if (NumVdwParams)
6811  {
6812  a1 = new Real[NumVdwParams];
6813  a2 = new Real[NumVdwParams];
6814  a3 = new Real[NumVdwParams];
6815  a4 = new Real[NumVdwParams];
6816 
6817  if ( (a1 == NULL) || (a2 == NULL) || (a3 == NULL) )
6818  {
6819  NAMD_die("memory allocation failed in Parameters::send_Parameters");
6820  }
6821 
6822  for (i=0; i<NumVdwParams; i++)
6823  {
6824  a1[i] = vdw_array[i].sigma;
6825  a2[i] = vdw_array[i].epsilon;
6826  a3[i] = vdw_array[i].sigma14;
6827  a4[i] = vdw_array[i].epsilon14;
6828  }
6829 
6830  msg->put(NumVdwParams * (MAX_ATOMTYPE_CHARS+1), atomTypeNames);
6831  msg->put(NumVdwParams, a1);
6832  msg->put(NumVdwParams, a2);
6833  msg->put(NumVdwParams, a3);
6834  msg->put(NumVdwParams, a4);
6835 
6836  delete [] a1;
6837  delete [] a2;
6838  delete [] a3;
6839  delete [] a4;
6840  }
6841 
6842  // Send the vdw pair parameters
6843  msg->put(NumVdwPairParams);
6844 
6845  if (NumVdwPairParams)
6846  {
6847  a1 = new Real[NumVdwPairParams];
6848  a2 = new Real[NumVdwPairParams];
6849  a3 = new Real[NumVdwPairParams];
6850  a4 = new Real[NumVdwPairParams];
6851  i1 = new int[NumVdwPairParams];
6852  i2 = new int[NumVdwPairParams];
6853 
6854  if ( (a1 == NULL) || (a2 == NULL) || (a3 == NULL) || (a4 == NULL) ||
6855  (i1 == NULL) || (i2 == NULL) )
6856  {
6857  NAMD_die("memory allocation failed in Parameters::send_Parameters");
6858  }
6859 
6860  vdw_pair_to_arrays(i1, i2, a1, a2, a3, a4, 0, vdw_pair_tree);
6861 
6862  msg->put(NumVdwPairParams, i1)->put(NumVdwPairParams, i2);
6863  msg->put(NumVdwPairParams, a1);
6864  msg->put(NumVdwPairParams, a2)->put(NumVdwPairParams, a3);
6865  msg->put(NumVdwPairParams, a4);
6866  }
6867 
6868  // Send the nbthole pair parameters
6869  msg->put(NumNbtholePairParams);
6870 
6872  {
6873  a1 = new Real[NumNbtholePairParams];
6874  a2 = new Real[NumNbtholePairParams];
6875  a3 = new Real[NumNbtholePairParams];
6876  i1 = new int[NumNbtholePairParams];
6877  i2 = new int[NumNbtholePairParams];
6878 
6879  if ( (a1 == NULL) || (a2 == NULL) || (a3 == NULL) || (i1 == NULL) || (i2 == NULL) )
6880  {
6881  NAMD_die("memory allocation failed in Parameters::send_Parameters");
6882  }
6883 
6884  nbthole_pair_to_arrays(i1, i2, a1, a2, a3, 0, nbthole_pair_tree);
6885 
6886  for (i=0; i<NumNbtholePairParams; i++)
6887  {
6888  nbthole_array[i].ind1 = i1[i];
6889  nbthole_array[i].ind2 = i2[i];
6890  nbthole_array[i].alphai = a1[i];
6891  nbthole_array[i].alphaj = a2[i];
6892  nbthole_array[i].tholeij = a3[i];
6893  }
6894 
6896  msg->put(NumNbtholePairParams, a1);
6898  }
6899 
6900  // Send the table pair parameters
6901  //printf("Pairs: %i\n", NumTablePairParams);
6902  msg->put(NumTablePairParams);
6903 
6904  if (NumTablePairParams)
6905  {
6906  i1 = new int[NumTablePairParams];
6907  i2 = new int[NumTablePairParams];
6908  i3 = new int[NumTablePairParams];
6909 
6910  if ( (i3 == NULL) || (i1 == NULL) || (i2 == NULL) )
6911  {
6912  NAMD_die("memory allocation failed in Parameters::send_Parameters");
6913  }
6914 
6915  table_pair_to_arrays(i1, i2, i3, 0, tab_pair_tree);
6916 
6917  msg->put(NumTablePairParams, i1)->put(NumTablePairParams, i2);
6918  msg->put(NumTablePairParams, i3);
6919  }
6920 
6921  // send the hydrogen bond parameters
6922  // hbondParams.create_message(msg);
6923  msg->end();
6924  delete msg;
6925 }
int numenerentries
Definition: Parameters.h:322
int NumTablePairParams
Definition: Parameters.h:344
GromacsPairValue * gromacsPair_array
Definition: Parameters.h:318
int NumBondParams
Definition: Parameters.h:330
void end(void)
Definition: MStream.C:176
Real epsilon
Definition: Parameters.h:174
int NumVdwParams
Definition: Parameters.h:339
float Real
Definition: common.h:118
int NumVdwPairParams
Definition: Parameters.h:342
Real sigma14
Definition: Parameters.h:175
DihedralValue * dihedral_array
Definition: Parameters.h:314
int NumAngleParams
Definition: Parameters.h:331
CrosstermValue * crossterm_array
Definition: Parameters.h:316
IndexedVdwPair * vdw_pair_tree
Definition: Parameters.h:326
int NumDihedralParams
Definition: Parameters.h:333
IndexedNbtholePair * nbthole_pair_tree
Definition: Parameters.h:327
FourBodyConsts values[MAX_MULTIPLICITY]
Definition: Parameters.h:128
AngleValue * angle_array
Definition: Parameters.h:313
int NumNbtholePairParams
Definition: Parameters.h:343
#define MAX_MULTIPLICITY
Definition: Parameters.h:88
Real sigma
Definition: Parameters.h:173
int NumImproperParams
Definition: Parameters.h:334
int NumCrosstermParams
Definition: Parameters.h:335
ImproperValue * improper_array
Definition: Parameters.h:315
void NAMD_die(const char *err_msg)
Definition: common.C:147
int NumVdwParamsAssigned
Definition: Parameters.h:341
NbtholePairValue * nbthole_array
Definition: Parameters.h:321
FourBodyConsts values[MAX_MULTIPLICITY]
Definition: Parameters.h:134
VdwValue * vdw_array
Definition: Parameters.h:320
BigReal * table_ener
Definition: Parameters.h:325
BondValue * bond_array
Definition: Parameters.h:312
int NumGromacsPairParams
Definition: Parameters.h:337
Real epsilon14
Definition: Parameters.h:176
MOStream * put(char data)
Definition: MStream.h:112
Real theta0
Definition: Parameters.h:112
IndexedTablePair * tab_pair_tree
Definition: Parameters.h:328
#define MAX_ATOMTYPE_CHARS
Definition: Parameters.h:91
double BigReal
Definition: common.h:123

Member Data Documentation

◆ angle_array

AngleValue* Parameters::angle_array

◆ bond_array

BondValue* Parameters::bond_array

◆ columnsize

int Parameters::columnsize

Definition at line 324 of file Parameters.h.

Referenced by ComputeNonbondedUtil::select().

◆ crossterm_array

CrosstermValue* Parameters::crossterm_array

◆ dihedral_array

DihedralValue* Parameters::dihedral_array

◆ gromacsPair_array

GromacsPairValue* Parameters::gromacsPair_array

Definition at line 318 of file Parameters.h.

Referenced by done_reading_files(), receive_Parameters(), send_Parameters(), and ~Parameters().

◆ improper_array

ImproperValue* Parameters::improper_array

◆ nbthole_array

NbtholePairValue* Parameters::nbthole_array

Definition at line 321 of file Parameters.h.

Referenced by done_reading_files(), receive_Parameters(), and send_Parameters().

◆ nbthole_pair_tree

IndexedNbtholePair* Parameters::nbthole_pair_tree

Definition at line 327 of file Parameters.h.

Referenced by send_Parameters(), and ~Parameters().

◆ NumAngleParams

int Parameters::NumAngleParams

◆ NumBondParams

int Parameters::NumBondParams

◆ NumCosAngles

int Parameters::NumCosAngles

Definition at line 332 of file Parameters.h.

Referenced by print_param_summary().

◆ NumCrosstermParams

int Parameters::NumCrosstermParams

◆ NumDihedralParams

int Parameters::NumDihedralParams

◆ numenerentries

int Parameters::numenerentries

Definition at line 322 of file Parameters.h.

Referenced by read_ener_table(), receive_Parameters(), and send_Parameters().

◆ NumGromacsPairParams

int Parameters::NumGromacsPairParams

Definition at line 337 of file Parameters.h.

Referenced by done_reading_files(), receive_Parameters(), and send_Parameters().

◆ NumImproperParams

int Parameters::NumImproperParams

◆ NumNbtholePairParams

int Parameters::NumNbtholePairParams

◆ NumTablePairParams

int Parameters::NumTablePairParams

◆ NumTableParams

int Parameters::NumTableParams

Definition at line 340 of file Parameters.h.

◆ NumVdwPairParams

int Parameters::NumVdwPairParams

◆ NumVdwParams

int Parameters::NumVdwParams

◆ NumVdwParamsAssigned

int Parameters::NumVdwParamsAssigned

◆ rowsize

int Parameters::rowsize

Definition at line 323 of file Parameters.h.

Referenced by ComputeNonbondedUtil::select().

◆ tab_pair_tree

IndexedTablePair* Parameters::tab_pair_tree

◆ table_ener

BigReal* Parameters::table_ener

◆ tablenumtypes

int Parameters::tablenumtypes

Definition at line 329 of file Parameters.h.

Referenced by get_int_table_type(), and read_ener_table().

◆ vdw_array

VdwValue* Parameters::vdw_array

◆ vdw_pair_tree

IndexedVdwPair* Parameters::vdw_pair_tree

The documentation for this class was generated from the following files: