NAMD
Classes | Typedefs | Functions
AmberParm7Reader Namespace Reference

Classes

struct  FortranFormatSpecifier
 
struct  FortranData
 
struct  Ambertoppar
 

Typedefs

typedef unordered_map< string,
tuple< bool, vector
< FortranData > > > 
AmberTopparMap
 

Functions

void parse_fortran_format (const std::string &str, FortranFormatSpecifier &specifier)
 Parse a single fortran format specifier. More...
 
void split_string (const std::string &data, const std::string &delim, std::vector< std::string > &dest)
 
void parse_fortran_format (const std::string &str, vector< FortranFormatSpecifier > &specifiers)
 Parse multiple fortran format specifiers separated by commas. More...
 
void split_string_by_specifiers (const string &source, const vector< FortranFormatSpecifier > &specifiers, vector< FortranData > &destination)
 This function splits a string by a set of fortran format specifiers. More...
 
bool read_amber_parm_stage1 (const char *filename, AmberTopparMap &toppar_map)
 Read an AMBER topology file into an AmberTopparMap. More...
 
bool read_amber_parm_stage2 (AmberTopparMap &toppar_map, Ambertoppar &toppar_data)
 Read an AmberTopparMap into an Ambertoppar struct for NAMD. More...
 
bool parse_pointer (const vector< FortranData > &source, Ambertoppar &result)
 
bool parse_section (const vector< FortranData > &source, const int &count, vector< string > &destination, const string &section_name)
 Copy data from source to destination. More...
 
bool parse_section (const vector< FortranData > &source, const int &count, vector< int > &destination, const string &section_name)
 
bool parse_section (const vector< FortranData > &source, const int &count, vector< _REAL > &destination, const string &section_name)
 
bool parse_section (const vector< FortranData > &source, const int &count, std::initializer_list< std::reference_wrapper< vector< string >>> destination, const string &section_name)
 Copy data from source to multiple destination arrays. More...
 
bool parse_section (const vector< FortranData > &source, const int &count, std::initializer_list< std::reference_wrapper< vector< int >>> destination, const string &section_name)
 
bool parse_section (const vector< FortranData > &source, const int &count, std::initializer_list< std::reference_wrapper< vector< _REAL >>> destination, const string &section_name)
 
Ambertoppar readparm (const char *filename)
 

Typedef Documentation

typedef unordered_map<string, tuple<bool, vector<FortranData> > > AmberParm7Reader::AmberTopparMap

Definition at line 87 of file ReadAmberParm.h.

Function Documentation

void AmberParm7Reader::parse_fortran_format ( const std::string &  str,
FortranFormatSpecifier &  specifier 
)

Parse a single fortran format specifier.

A good documentation for fortran format specifiers can be found at: https://www.obliquity.com/computer/fortran/format.html. However, I don't plan to support all of them since that is too complicated and the AMBER parm7 files only use a subset of them. Here's a list of examples of the specifiers: 5E16.8: match 5 floating point numbers, with 16 as field width and 8 as precision. i2: match an integer with 2 as field width. a78: match a string with 78 characters. 20a4: match 20 strings and each string has 4 characters. This function can parse the a string of above into a FortranFormatSpecifier.

Parameters
stra specifier string.
specifiera fortran specifier struct.

Definition at line 15 of file ReadAmberParm.C.

References dot(), AmberParm7Reader::FortranFormatSpecifier::IsPadding, AmberParm7Reader::FortranFormatSpecifier::NumOfFields, AmberParm7Reader::FortranFormatSpecifier::Padding, AmberParm7Reader::FortranFormatSpecifier::Precision, AmberParm7Reader::FortranFormatSpecifier::Type, and AmberParm7Reader::FortranFormatSpecifier::Width.

Referenced by parse_fortran_format(), and read_amber_parm_stage1().

16  {
17  size_t left_quotation_mark = str.find("'");
18  if (left_quotation_mark == std::string::npos) {
19  std::string num_fields, type, width, dot, precision;
20  for (size_t i = 0; i < str.size(); ++i) {
21  // check if this is a digit at first.
22  if (std::isdigit(str[i])) {
23  // then check if the digit is before or after the type.
24  if (type.size() > 0) {
25  // if type is already read,
26  // then append this character to "width" or "precision".
27  if (dot.size() > 0) {
28  // the digit after "." denotes the precision.
29  precision += str[i];
30  } else {
31  // the digit is after the type field but before ".".
32  width += str[i];
33  }
34  } else {
35  // the digit before the type represents the number of fields.
36  num_fields += str[i];
37  }
38  } else if (std::isalpha(str[i])) {
39  // if it is [A-Za-z] then it denotes the type.
40  type += str[i];
41  } else if (str[i] == '.') {
42  dot += str[i];
43  } else {
44  // skip other characters
45  continue;
46  }
47  }
48  // populate the FortranFormatSpecifier struct
49  if (num_fields.size() > 0) {
50  specifier.NumOfFields = std::stoul(num_fields.c_str());
51  } else {
52  // ("i10", "E6.2")
53  specifier.NumOfFields = 1;
54  }
55  // must have "type"
56  specifier.Type = type.front();
57  // must have "width"
58  specifier.Width = std::stoul(width.c_str());
59  if (precision.size() > 0) {
60  specifier.Precision = std::stoul(precision.c_str());
61  } else {
62  // integers have no precision fields
63  specifier.Precision = -1;
64  }
65  } else {
66  size_t right_quotation_mark = str.find("'", left_quotation_mark + 1);
67  specifier.IsPadding = true;
68  specifier.Padding =
69  str.substr(left_quotation_mark + 1,
70  right_quotation_mark - (left_quotation_mark + 1));
71  specifier.NumOfFields = 1;
72  }
73 }
__device__ __forceinline__ float dot(const float3 v1, const float3 v2)
void AmberParm7Reader::parse_fortran_format ( const std::string &  str,
vector< FortranFormatSpecifier > &  specifiers 
)

Parse multiple fortran format specifiers separated by commas.

Parameters
stra specifier string. For example: "i2,a78".
specifiersa vector of fortran specifier structs.

Definition at line 93 of file ReadAmberParm.C.

References parse_fortran_format(), and split_string().

94  {
95  // split the string by comma
96  vector<string> sub_format_strings;
97  split_string(str, ",", sub_format_strings);
98  specifiers.resize(sub_format_strings.size());
99  for (size_t i = 0; i < sub_format_strings.size(); ++i) {
100  parse_fortran_format(sub_format_strings[i], specifiers[i]);
101  }
102 }
void parse_fortran_format(const std::string &str, FortranFormatSpecifier &specifier)
Parse a single fortran format specifier.
Definition: ReadAmberParm.C:15
void split_string(const std::string &data, const std::string &delim, std::vector< std::string > &dest)
Definition: ReadAmberParm.C:76
bool AmberParm7Reader::parse_pointer ( const vector< FortranData > &  source,
Ambertoppar result 
)

Definition at line 1116 of file ReadAmberParm.C.

References AmberParm7Reader::Ambertoppar::AngleAt1, AmberParm7Reader::Ambertoppar::AngleAt2, AmberParm7Reader::Ambertoppar::AngleAt3, AmberParm7Reader::Ambertoppar::AngleHAt1, AmberParm7Reader::Ambertoppar::AngleHAt2, AmberParm7Reader::Ambertoppar::AngleHAt3, AmberParm7Reader::Ambertoppar::AngleHNum, AmberParm7Reader::Ambertoppar::AngleNum, AmberParm7Reader::Ambertoppar::AtomNames, AmberParm7Reader::Ambertoppar::AtomNumbers, AmberParm7Reader::Ambertoppar::AtomRes, AmberParm7Reader::Ambertoppar::AtomSym, AmberParm7Reader::Ambertoppar::AtomTree, AmberParm7Reader::Ambertoppar::BondAt1, AmberParm7Reader::Ambertoppar::BondAt2, AmberParm7Reader::Ambertoppar::BondHAt1, AmberParm7Reader::Ambertoppar::BondHAt2, AmberParm7Reader::Ambertoppar::BondHNum, AmberParm7Reader::Ambertoppar::BondNum, AmberParm7Reader::Ambertoppar::Charges, AmberParm7Reader::Ambertoppar::Cn1, AmberParm7Reader::Ambertoppar::Cn2, AmberParm7Reader::Ambertoppar::Cno, AmberParm7Reader::Ambertoppar::DihAt1, AmberParm7Reader::Ambertoppar::DihAt2, AmberParm7Reader::Ambertoppar::DihAt3, AmberParm7Reader::Ambertoppar::DihAt4, AmberParm7Reader::Ambertoppar::DihHAt1, AmberParm7Reader::Ambertoppar::DihHAt2, AmberParm7Reader::Ambertoppar::DihHAt3, AmberParm7Reader::Ambertoppar::DihHAt4, AmberParm7Reader::Ambertoppar::DihHNum, AmberParm7Reader::Ambertoppar::DihNum, AmberParm7Reader::Ambertoppar::ExclAt, AmberParm7Reader::Ambertoppar::HB10, AmberParm7Reader::Ambertoppar::HB12, AmberParm7Reader::Ambertoppar::Iac, AmberParm7Reader::Ambertoppar::Iblo, AmberParm7Reader::Ambertoppar::Ifbox, AmberParm7Reader::Ambertoppar::Ifcap, AmberParm7Reader::Ambertoppar::Ifpert, AmberParm7Reader::Ambertoppar::Ipres, AmberParm7Reader::Ambertoppar::Masses, AmberParm7Reader::Ambertoppar::Mbona, AmberParm7Reader::Ambertoppar::Mbper, AmberParm7Reader::Ambertoppar::Mdper, AmberParm7Reader::Ambertoppar::Mgper, AmberParm7Reader::Ambertoppar::Mphia, AmberParm7Reader::Ambertoppar::Mtheta, AmberParm7Reader::Ambertoppar::Natom, AmberParm7Reader::Ambertoppar::Natyp, AmberParm7Reader::Ambertoppar::Nbona, AmberParm7Reader::Ambertoppar::Nbonh, AmberParm7Reader::Ambertoppar::Nbper, AmberParm7Reader::Ambertoppar::Ncopy, AmberParm7Reader::Ambertoppar::Ndper, AmberParm7Reader::Ambertoppar::Ngper, AmberParm7Reader::Ambertoppar::Nhparm, AmberParm7Reader::Ambertoppar::Nmxrs, AmberParm7Reader::Ambertoppar::Nnb, AmberParm7Reader::Ambertoppar::Nparm, AmberParm7Reader::Ambertoppar::Nphb, AmberParm7Reader::Ambertoppar::Nphia, AmberParm7Reader::Ambertoppar::Nphih, AmberParm7Reader::Ambertoppar::Nptra, AmberParm7Reader::Ambertoppar::Nres, AmberParm7Reader::Ambertoppar::Ntheta, AmberParm7Reader::Ambertoppar::Ntheth, AmberParm7Reader::Ambertoppar::Ntypes, AmberParm7Reader::Ambertoppar::Numang, AmberParm7Reader::Ambertoppar::Numbnd, AmberParm7Reader::Ambertoppar::Numextra, AmberParm7Reader::Ambertoppar::Phase, AmberParm7Reader::Ambertoppar::Pk, AmberParm7Reader::Ambertoppar::Pn, AmberParm7Reader::Ambertoppar::Radii, AmberParm7Reader::Ambertoppar::RadiusSet, AmberParm7Reader::Ambertoppar::Req, AmberParm7Reader::Ambertoppar::ResNames, AmberParm7Reader::Ambertoppar::Rk, AmberParm7Reader::Ambertoppar::SceeScaleFactor, AmberParm7Reader::Ambertoppar::ScnbScaleFactor, AmberParm7Reader::Ambertoppar::Screen, AmberParm7Reader::Ambertoppar::Solty, AmberParm7Reader::Ambertoppar::Teq, AmberParm7Reader::Ambertoppar::Tk, and AmberParm7Reader::Ambertoppar::TreeJoin.

Referenced by read_amber_parm_stage2().

1116  {
1117  bool success = true;
1118  if (source.size() > 30) {
1119  result.Natom = source[0].Int;
1120  result.Ntypes = source[1].Int;
1121  result.Nbonh = source[2].Int;
1122  result.Mbona = source[3].Int;
1123  result.Ntheth = source[4].Int;
1124  result.Mtheta = source[5].Int;
1125  result.Nphih = source[6].Int;
1126  result.Mphia = source[7].Int;
1127  result.Nhparm = source[8].Int;
1128  result.Nparm = source[9].Int;
1129  result.Nnb = source[10].Int;
1130  result.Nres = source[11].Int;
1131  result.Nbona = source[12].Int;
1132  result.Ntheta = source[13].Int;
1133  result.Nphia = source[14].Int;
1134  result.Numbnd = source[15].Int;
1135  result.Numang = source[16].Int;
1136  result.Nptra = source[17].Int;
1137  result.Natyp = source[18].Int;
1138  result.Nphb = source[19].Int;
1139  result.Ifpert = source[20].Int;
1140  result.Nbper = source[21].Int;
1141  result.Ngper = source[22].Int;
1142  result.Ndper = source[23].Int;
1143  result.Mbper = source[24].Int;
1144  result.Mgper = source[25].Int;
1145  result.Mdper = source[26].Int;
1146  result.Ifbox = source[27].Int;
1147  result.Nmxrs = source[28].Int;
1148  result.Ifcap = source[29].Int;
1149  result.Numextra = source[30].Int;
1150  // Ncopy may not be present
1151  result.Ncopy = 31 < source.size() ? source[31].Int : 0;
1152  // "allocate memory"
1153  const int Ntype2d = result.Ntypes * result.Ntypes;
1154  const int Nttyp = result.Ntypes * (result.Ntypes + 1) / 2;
1155  result.AtomNames.reserve(result.Natom);
1156  result.Charges.reserve(result.Natom);
1157  result.Masses.reserve(result.Natom);
1158  result.AtomNumbers.reserve(result.Natom);
1159  result.Iac.reserve(result.Natom);
1160  result.Iblo.reserve(result.Natom);
1161  result.Cno.reserve(Ntype2d);
1162  result.ResNames.reserve(result.Nres);
1163  result.Ipres.reserve(result.Nres);
1164  result.Rk.reserve(result.Numbnd);
1165  result.Req.reserve(result.Numbnd);
1166  result.Tk.reserve(result.Numang);
1167  result.Teq.reserve(result.Numang);
1168  result.Pk.reserve(result.Nptra);
1169  result.Pn.reserve(result.Nptra);
1170  result.Phase.reserve(result.Nptra);
1171  result.SceeScaleFactor.reserve(result.Nptra);
1172  result.ScnbScaleFactor.reserve(result.Nptra);
1173  result.Solty.reserve(result.Natyp);
1174  result.Cn1.reserve(Nttyp);
1175  result.Cn2.reserve(Nttyp);
1176  result.BondHAt1.reserve(result.Nbonh);
1177  result.BondHAt2.reserve(result.Nbonh);
1178  result.BondHNum.reserve(result.Nbonh);
1179  result.BondAt1.reserve(result.Nbona);
1180  result.BondAt2.reserve(result.Nbona);
1181  result.BondNum.reserve(result.Nbona);
1182  result.AngleHAt1.reserve(result.Ntheth);
1183  result.AngleHAt2.reserve(result.Ntheth);
1184  result.AngleHAt3.reserve(result.Ntheth);
1185  result.AngleHNum.reserve(result.Ntheth);
1186  result.AngleAt1.reserve(result.Ntheta);
1187  result.AngleAt2.reserve(result.Ntheta);
1188  result.AngleAt3.reserve(result.Ntheta);
1189  result.AngleNum.reserve(result.Ntheta);
1190  result.DihHAt1.reserve(result.Nphih);
1191  result.DihHAt2.reserve(result.Nphih);
1192  result.DihHAt3.reserve(result.Nphih);
1193  result.DihHAt4.reserve(result.Nphih);
1194  result.DihHNum.reserve(result.Nphih);
1195  result.DihAt1.reserve(result.Nphia);
1196  result.DihAt2.reserve(result.Nphia);
1197  result.DihAt3.reserve(result.Nphia);
1198  result.DihAt4.reserve(result.Nphia);
1199  result.DihNum.reserve(result.Nphia);
1200  result.ExclAt.reserve(result.Nnb);
1201  result.HB12.reserve(result.Nphb);
1202  result.HB10.reserve(result.Nphb);
1203  result.AtomSym.reserve(result.Natom);
1204  result.AtomTree.reserve(result.Natom);
1205  result.TreeJoin.reserve(result.Natom);
1206  result.AtomRes.reserve(result.Natom);
1207  result.RadiusSet.reserve(1);
1208  result.Radii.reserve(result.Natom);
1209  result.Screen.reserve(result.Natom);
1210  } else {
1211  success = false;
1212  }
1213  return success;
1214 }
_REAL * Pk
Definition: parm.h:24
int * DihHAt1
Definition: parm.h:27
_REAL * Teq
Definition: parm.h:24
char * AtomTree
Definition: parm.h:23
int * BondHNum
Definition: parm.h:27
int * DihAt3
Definition: parm.h:27
int Natom
Definition: parm.h:17
_REAL * Phase
Definition: parm.h:24
int Natyp
Definition: parm.h:17
int Nphih
Definition: parm.h:17
int * AngleHNum
Definition: parm.h:27
int Mtheta
Definition: parm.h:17
int * BondAt2
Definition: parm.h:27
int Nbonh
Definition: parm.h:17
int * DihHAt4
Definition: parm.h:27
_REAL * Tk
Definition: parm.h:24
int Mbona
Definition: parm.h:17
int Nhparm
Definition: parm.h:17
int * Iblo
Definition: parm.h:27
char * ResNames
Definition: parm.h:23
int * DihAt4
Definition: parm.h:27
int Mphia
Definition: parm.h:17
_REAL * Masses
Definition: parm.h:24
int * AngleHAt1
Definition: parm.h:27
int Numbnd
Definition: parm.h:17
_REAL * HB12
Definition: parm.h:24
int * AngleNum
Definition: parm.h:27
int * DihHNum
Definition: parm.h:27
int * Iac
Definition: parm.h:27
_REAL * Charges
Definition: parm.h:24
int Ntypes
Definition: parm.h:17
int * DihAt1
Definition: parm.h:27
int * BondNum
Definition: parm.h:27
int * DihNum
Definition: parm.h:27
int Nbona
Definition: parm.h:17
int Nmxrs
Definition: parm.h:17
int * BondHAt1
Definition: parm.h:27
int * AngleHAt3
Definition: parm.h:27
char * AtomNames
Definition: parm.h:23
_REAL * Cn2
Definition: parm.h:24
int * AtomRes
Definition: parm.h:27
int Ntheta
Definition: parm.h:17
int * AngleAt3
Definition: parm.h:27
int * AngleAt1
Definition: parm.h:27
int Nparm
Definition: parm.h:17
char * AtomSym
Definition: parm.h:23
int * BondAt1
Definition: parm.h:27
int Ntheth
Definition: parm.h:17
_REAL * Rk
Definition: parm.h:24
int Nnb
Definition: parm.h:17
int * DihHAt2
Definition: parm.h:27
int Nphb
Definition: parm.h:17
_REAL * Cn1
Definition: parm.h:24
int * TreeJoin
Definition: parm.h:27
int * DihAt2
Definition: parm.h:27
int Numang
Definition: parm.h:17
_REAL * Req
Definition: parm.h:24
_REAL * Solty
Definition: parm.h:24
int Nphia
Definition: parm.h:17
int * AngleAt2
Definition: parm.h:27
int * ExclAt
Definition: parm.h:27
int * AngleHAt2
Definition: parm.h:27
int Nres
Definition: parm.h:17
int * Ipres
Definition: parm.h:27
int Nptra
Definition: parm.h:17
int * BondHAt2
Definition: parm.h:27
int * Cno
Definition: parm.h:27
_REAL * Pn
Definition: parm.h:24
int * DihHAt3
Definition: parm.h:27
bool AmberParm7Reader::parse_section ( const vector< FortranData > &  source,
const int &  count,
vector< string > &  destination,
const string &  section_name 
)

Copy data from source to destination.

Parameters
sourcesource data from AmberTopparMap.
countthe number of fields. It should equal to the size of source.
destinationdestination array in Ambertoppar.
section_namename of the section (used for sanity check only).
Returns
read status. It will return 0 if the reading is successful.

Definition at line 1216 of file ReadAmberParm.C.

References endi(), iERROR(), iINFO(), and iout.

Referenced by read_amber_parm_stage2().

1217  {
1218  bool success = true;
1219  if (int(source.size()) != count) {
1220  iout << iERROR << "Expect " << count << " fields but only "
1221  << source.size() << " are in "
1222  << section_name.c_str() << "\n";
1223  success = false;
1224  } else {
1225  for (int i = 0; i < count; ++i) {
1226  destination.push_back(source[i].String);
1227  }
1228  iout << iINFO << "Complete reading " << section_name.c_str() << " with " << count << " fields.\n" << endi;
1229  }
1230  return success;
1231 }
std::ostream & iINFO(std::ostream &s)
Definition: InfoStream.C:81
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
#define iout
Definition: InfoStream.h:51
std::ostream & iERROR(std::ostream &s)
Definition: InfoStream.C:83
bool AmberParm7Reader::parse_section ( const vector< FortranData > &  source,
const int &  count,
vector< int > &  destination,
const string &  section_name 
)

Definition at line 1233 of file ReadAmberParm.C.

References endi(), iERROR(), iINFO(), and iout.

1234  {
1235  bool success = true;
1236  if (int(source.size()) != count) {
1237  iout << iERROR << "Expect " << count << " fields but only "
1238  << source.size() << " are in "
1239  << section_name.c_str() << "\n";
1240  success = false;
1241  } else {
1242  for (int i = 0; i < count; ++i) {
1243  destination.push_back(source[i].Int);
1244  }
1245  iout << iINFO << "Complete reading " << section_name.c_str() << " with " << count << " fields.\n" << endi;
1246  }
1247  return success;
1248 }
std::ostream & iINFO(std::ostream &s)
Definition: InfoStream.C:81
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
#define iout
Definition: InfoStream.h:51
std::ostream & iERROR(std::ostream &s)
Definition: InfoStream.C:83
bool AmberParm7Reader::parse_section ( const vector< FortranData > &  source,
const int &  count,
vector< _REAL > &  destination,
const string &  section_name 
)

Definition at line 1250 of file ReadAmberParm.C.

References endi(), iERROR(), iINFO(), and iout.

1251  {
1252  bool success = true;
1253  if (int(source.size()) != count) {
1254  iout << iERROR << "Expect " << count << " fields but only "
1255  << source.size() << " are in "
1256  << section_name.c_str() << "\n";
1257  success = false;
1258  } else {
1259  for (int i = 0; i < count; ++i) {
1260  destination.push_back(source[i].Real);
1261  }
1262  iout << iINFO << "Complete reading " << section_name.c_str() << " with " << count << " fields.\n" << endi;
1263  }
1264  return success;
1265 }
std::ostream & iINFO(std::ostream &s)
Definition: InfoStream.C:81
float Real
Definition: common.h:109
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
#define iout
Definition: InfoStream.h:51
std::ostream & iERROR(std::ostream &s)
Definition: InfoStream.C:83
bool AmberParm7Reader::parse_section ( const vector< FortranData > &  source,
const int &  count,
std::initializer_list< std::reference_wrapper< vector< string >>>  destination,
const string &  section_name 
)

Copy data from source to multiple destination arrays.

Assuming the size of destination list is M, the size of the source array should be M * count. This function copies source[M*i+j] to destination[j][i].

Parameters
sourcesource data from AmberTopparMap.
countthe number of fields. It should equal to the size of source divided by the size of destination.
destinationmultiple destination arrays in Ambertoppar.
section_namename of the section (used for sanity check only).

Definition at line 1267 of file ReadAmberParm.C.

References endi(), iERROR(), iINFO(), and iout.

1270  {
1271  bool success = true;
1272  const int total_size = destination.size() * count;
1273  if (int(source.size()) != total_size) {
1274  iout << iERROR << "Expect " << total_size << " fields but only "
1275  << source.size() << " are in "
1276  << section_name.c_str() << "\n";
1277  success = false;
1278  } else {
1279  const int stride = destination.size();
1280  for (int i = 0; i < count; ++i) {
1281  int j = 0;
1282  for (auto it_j = destination.begin(); it_j != destination.end(); ++it_j) {
1283  it_j->get().push_back(source[stride * i + j].String);
1284  ++j;
1285  }
1286  }
1287  iout << iINFO << "Complete reading " << section_name.c_str() << " with " << total_size << " fields.\n" << endi;
1288  }
1289  return success;
1290 }
std::ostream & iINFO(std::ostream &s)
Definition: InfoStream.C:81
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
#define iout
Definition: InfoStream.h:51
std::ostream & iERROR(std::ostream &s)
Definition: InfoStream.C:83
bool AmberParm7Reader::parse_section ( const vector< FortranData > &  source,
const int &  count,
std::initializer_list< std::reference_wrapper< vector< int >>>  destination,
const string &  section_name 
)

Definition at line 1292 of file ReadAmberParm.C.

References endi(), iERROR(), iINFO(), and iout.

1295  {
1296  bool success = true;
1297  const int total_size = destination.size() * count;
1298  if (int(source.size()) != total_size) {
1299  iout << iERROR << "Expect " << total_size << " fields but only "
1300  << source.size() << " are in "
1301  << section_name.c_str() << "\n";
1302  success = false;
1303  } else {
1304  const int stride = destination.size();
1305  for (int i = 0; i < count; ++i) {
1306  int j = 0;
1307  for (auto it_j = destination.begin(); it_j != destination.end(); ++it_j) {
1308  it_j->get().push_back(source[stride * i + j].Int);
1309  ++j;
1310  }
1311  }
1312  iout << iINFO << "Complete reading " << section_name.c_str() << " with " << total_size << " fields.\n" << endi;
1313  }
1314  return success;
1315 }
std::ostream & iINFO(std::ostream &s)
Definition: InfoStream.C:81
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
#define iout
Definition: InfoStream.h:51
std::ostream & iERROR(std::ostream &s)
Definition: InfoStream.C:83
bool AmberParm7Reader::parse_section ( const vector< FortranData > &  source,
const int &  count,
std::initializer_list< std::reference_wrapper< vector< _REAL >>>  destination,
const string &  section_name 
)

Definition at line 1317 of file ReadAmberParm.C.

References endi(), iERROR(), iINFO(), and iout.

1320  {
1321  bool success = true;
1322  const int total_size = destination.size() * count;
1323  if (int(source.size()) != total_size) {
1324  iout << iERROR << "Expect " << total_size << " fields but only "
1325  << source.size() << " are in "
1326  << section_name.c_str() << "\n";
1327  success = false;
1328  } else {
1329  const int stride = destination.size();
1330  for (int i = 0; i < count; ++i) {
1331  int j = 0;
1332  for (auto it_j = destination.begin(); it_j != destination.end(); ++it_j) {
1333  it_j->get().push_back(source[stride * i + j].Real);
1334  ++j;
1335  }
1336  }
1337  iout << iINFO << "Complete reading " << section_name.c_str() << " with " << total_size << " fields.\n" << endi;
1338  }
1339  return success;
1340 }
std::ostream & iINFO(std::ostream &s)
Definition: InfoStream.C:81
float Real
Definition: common.h:109
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
#define iout
Definition: InfoStream.h:51
std::ostream & iERROR(std::ostream &s)
Definition: InfoStream.C:83
bool AmberParm7Reader::read_amber_parm_stage1 ( const char *  filename,
AmberTopparMap &  toppar_map 
)

Read an AMBER topology file into an AmberTopparMap.

Parameters
filenamethe filename of the AMBER topology file.
toppar_mapa map contains the FLAG title and the data.
Returns
read status. It will return 0 if the reading is successful.

Definition at line 142 of file ReadAmberParm.C.

References parse_fortran_format(), and split_string_by_specifiers().

Referenced by readparm().

142  {
143  using std::ifstream;
144  using std::istringstream;
145  using std::string;
146  bool success = true;
147  string error_msg;
148  ifstream ifs_parm(filename);
149  if (!ifs_parm.is_open()) return false;
150  string line;
151  string current_flag;
152  bool match_flag = false;
153  bool match_format = false;
154  // vector<FortranData> section_data;
155  vector<FortranFormatSpecifier> specifiers;
156  tuple<bool, vector<FortranData>> *p_map = nullptr;
157  istringstream iss;
158  while (std::getline(ifs_parm, line)) {
159  /* AMBER format parser requirement 3:
160  * Parsers should not expect or require %COMMENT lines to exist,
161  * but should properly parse the file if any number of %COMMENT
162  * lines appear as indicated above.
163  */
164  if (line[0] == '%') {
165  if (line.find("%COMMENT") == 0) {
166  continue;
167  } else if (line.find("%VERSION") == 0) {
168  // parse the version line, read version_stamp and build time
169  char tmp_version_stamp[16];
170  char tmp_date[16];
171  char tmp_time[16];
172  if (sscanf(line.c_str(), "%%VERSION VERSION_STAMP = %9s DATE = %8s %8s",
173  tmp_version_stamp, tmp_date, tmp_time) == 3) {
174  continue;
175  } else {
176  return false;
177  }
178  } else if (line.find("%FLAG") == 0) {
179  // parse flags
180  if (match_flag && match_format) {
181  // insert the previous section into map
182  current_flag.clear();
183  specifiers.clear();
184  match_flag = false;
185  match_format = false;
186  }
187  istringstream iss(line.substr(strlen("%FLAG")));
188  iss >> current_flag;
189  p_map = &(toppar_map[current_flag]);
190  std::get<0>(*p_map) = false;
191  match_flag = true;
192  continue;
193  } else if (line.find("%FORMAT") == 0) {
194  // parse format
195  if (match_flag == false) {
196  success = false;
197  break;
198  }
199  const size_t format_start = line.find("(", strlen("%FORMAT"));
200  const size_t format_end = line.find(")", format_start + 1);
202  line.substr(format_start + 1, format_end - (format_start + 1)),
203  specifiers);
204  match_format = true;
205  continue;
206  }
207  }
208  // parse data fields
209  if (match_flag && match_format) {
210  // read the according section
211  split_string_by_specifiers(line, specifiers, std::get<1>(*p_map));
212  }
213  }
214  return success;
215 }
void split_string_by_specifiers(const string &source, const vector< FortranFormatSpecifier > &specifiers, vector< FortranData > &destination)
This function splits a string by a set of fortran format specifiers.
void parse_fortran_format(const std::string &str, FortranFormatSpecifier &specifier)
Parse a single fortran format specifier.
Definition: ReadAmberParm.C:15
bool AmberParm7Reader::read_amber_parm_stage2 ( AmberTopparMap &  toppar_map,
Ambertoppar toppar_data 
)

Read an AmberTopparMap into an Ambertoppar struct for NAMD.

Parameters
toppar_mapa map contains the FLAG title and the data
toppar_dataan Ambertoppar struct for NAMD.
Returns
read status. It will return 0 if the reading is successful.

Definition at line 217 of file ReadAmberParm.C.

References AmberParm7Reader::Ambertoppar::AtomNames, AmberParm7Reader::Ambertoppar::AtomNumbers, AmberParm7Reader::Ambertoppar::BondHAt1, AmberParm7Reader::Ambertoppar::BondHAt2, AmberParm7Reader::Ambertoppar::BondHNum, AmberParm7Reader::Ambertoppar::Charges, AmberParm7Reader::Ambertoppar::Cn1, AmberParm7Reader::Ambertoppar::Cn2, AmberParm7Reader::Ambertoppar::Cno, endi(), AmberParm7Reader::Ambertoppar::Iac, AmberParm7Reader::Ambertoppar::Iblo, iERROR(), iout, AmberParm7Reader::Ambertoppar::Ipres, AmberParm7Reader::Ambertoppar::IsCharmmFF, AmberParm7Reader::Ambertoppar::ititl, iWARN(), AmberParm7Reader::Ambertoppar::Masses, AmberParm7Reader::Ambertoppar::Natom, AmberParm7Reader::Ambertoppar::Nbonh, AmberParm7Reader::Ambertoppar::Nptra, AmberParm7Reader::Ambertoppar::Nres, AmberParm7Reader::Ambertoppar::Ntypes, AmberParm7Reader::Ambertoppar::Numang, AmberParm7Reader::Ambertoppar::Numbnd, parse_pointer(), parse_section(), AmberParm7Reader::Ambertoppar::Phase, AmberParm7Reader::Ambertoppar::Pk, AmberParm7Reader::Ambertoppar::Pn, AmberParm7Reader::Ambertoppar::Req, AmberParm7Reader::Ambertoppar::ResNames, AmberParm7Reader::Ambertoppar::Rk, AmberParm7Reader::Ambertoppar::SceeScaleFactor, AmberParm7Reader::Ambertoppar::ScnbScaleFactor, AmberParm7Reader::Ambertoppar::Teq, and AmberParm7Reader::Ambertoppar::Tk.

Referenced by readparm().

218  {
219  using std::get;
220  using std::ref;
221  bool success = true;
222  // TITLE
223  {
224  // check TITLE to see if this is a AMBER force field
225  auto current_section = toppar_map.find("TITLE");
226  if (current_section == toppar_map.end()) {
227  // check if this is a CHARMM force field in AMBER format
228  current_section = toppar_map.find("CTITLE");
229  if (current_section == toppar_map.end()) {
230  iout << iERROR << "TITLE/CTITLE section for AMBER/CHARMM force field is not "
231  "found!\n" << endi;
232  toppar_data.IsCharmmFF = false;
233  success = false;
234  iout << iERROR << "Failed to read the title section!\n" << endi;
235  } else {
236  iout << iWARN << "You are using CHARMM force field in AMBER format, which is not supported in NAMD!\n" << endi;
237  toppar_data.IsCharmmFF = true;
238  }
239  } else {
240  toppar_data.IsCharmmFF = false;
241  }
242  toppar_data.ititl = get<1>(current_section->second).size() > 0 ? get<1>(current_section->second)[0].String : string();
243  get<0>(current_section->second) = true;
244  }
245  // POINTERS
246  if (success) {
247  const string section_name{"POINTERS"};
248  const auto &current_section = toppar_map.find(section_name);
249  if (current_section != toppar_map.end()) {
250  success = parse_pointer(get<1>(current_section->second), toppar_data);
251  get<0>(current_section->second) = true;
252  } else {
253  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
254  }
255  }
256  // ATOM_NAME
257  if (success) {
258  const string section_name{"ATOM_NAME"};
259  const auto &current_section = toppar_map.find(section_name);
260  if (current_section != toppar_map.end()) {
261  success = parse_section(get<1>(current_section->second), toppar_data.Natom,
262  toppar_data.AtomNames, section_name);
263  get<0>(current_section->second) = true;
264  } else {
265  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
266  }
267  }
268  // CHARGE
269  if (success) {
270  const string section_name{"CHARGE"};
271  const auto &current_section = toppar_map.find(section_name);
272  if (current_section != toppar_map.end()) {
273  success = parse_section(get<1>(current_section->second), toppar_data.Natom,
274  toppar_data.Charges, section_name);
275  get<0>(current_section->second) = true;
276  } else {
277  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
278  }
279  }
280  // ATOMIC_NUMBER
281  if (success) {
282  const string section_name{"ATOMIC_NUMBER"};
283  const auto &current_section = toppar_map.find(section_name);
284  if (current_section != toppar_map.end()) {
285  success = parse_section(get<1>(current_section->second), toppar_data.Natom,
286  toppar_data.AtomNumbers, section_name);
287  get<0>(current_section->second) = true;
288  } else {
289  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
290  }
291  }
292  // MASS
293  if (success) {
294  const string section_name{"MASS"};
295  const auto &current_section = toppar_map.find(section_name);
296  if (current_section != toppar_map.end()) {
297  success = parse_section(get<1>(current_section->second), toppar_data.Natom,
298  toppar_data.Masses, section_name);
299  get<0>(current_section->second) = true;
300  } else {
301  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
302  }
303  }
304  // ATOM_TYPE_INDEX
305  if (success) {
306  const string section_name{"ATOM_TYPE_INDEX"};
307  const auto &current_section = toppar_map.find(section_name);
308  if (current_section != toppar_map.end()) {
309  success = parse_section(get<1>(current_section->second), toppar_data.Natom,
310  toppar_data.Iac, section_name);
311  get<0>(current_section->second) = true;
312  } else {
313  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
314  }
315  }
316  // NUMBER_EXCLUDED_ATOMS
317  if (success) {
318  const string section_name{"NUMBER_EXCLUDED_ATOMS"};
319  const auto &current_section = toppar_map.find(section_name);
320  if (current_section != toppar_map.end()) {
321  success = parse_section(get<1>(current_section->second), toppar_data.Natom,
322  toppar_data.Iblo, section_name);
323  get<0>(current_section->second) = true;
324  } else {
325  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
326  }
327  }
328  // NONBONDED_PARM_INDEX
329  if (success) {
330  const int Ntype2d = toppar_data.Ntypes * toppar_data.Ntypes;
331  const string section_name{"NONBONDED_PARM_INDEX"};
332  const auto &current_section = toppar_map.find(section_name);
333  if (current_section != toppar_map.end()) {
334  success = parse_section(get<1>(current_section->second), Ntype2d, toppar_data.Cno,
335  section_name);
336  get<0>(current_section->second) = true;
337  } else {
338  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
339  }
340  }
341  // RESIDUE_LABEL
342  if (success) {
343  const string section_name{"RESIDUE_LABEL"};
344  const auto &current_section = toppar_map.find(section_name);
345  if (current_section != toppar_map.end()) {
346  success = parse_section(get<1>(current_section->second), toppar_data.Nres,
347  toppar_data.ResNames, section_name);
348  get<0>(current_section->second) = true;
349  } else {
350  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
351  }
352  }
353  // RESIDUE_POINTER
354  if (success) {
355  const string section_name{"RESIDUE_POINTER"};
356  const auto &current_section = toppar_map.find(section_name);
357  if (current_section != toppar_map.end()) {
358  success = parse_section(get<1>(current_section->second), toppar_data.Nres,
359  toppar_data.Ipres, section_name);
360  get<0>(current_section->second) = true;
361  } else {
362  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
363  }
364  }
365  // BOND_FORCE_CONSTANT
366  if (success) {
367  const string section_name{"BOND_FORCE_CONSTANT"};
368  const auto &current_section = toppar_map.find(section_name);
369  if (current_section != toppar_map.end()) {
370  success = parse_section(get<1>(current_section->second), toppar_data.Numbnd,
371  toppar_data.Rk, section_name);
372  get<0>(current_section->second) = true;
373  } else {
374  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
375  }
376  }
377  // BOND_EQUIL_VALUE
378  if (success) {
379  const string section_name{"BOND_EQUIL_VALUE"};
380  const auto &current_section = toppar_map.find(section_name);
381  if (current_section != toppar_map.end()) {
382  success = parse_section(get<1>(current_section->second), toppar_data.Numbnd,
383  toppar_data.Req, section_name);
384  get<0>(current_section->second) = true;
385  } else {
386  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
387  }
388  }
389  // ANGLE_FORCE_CONSTANT
390  if (success) {
391  const string section_name{"ANGLE_FORCE_CONSTANT"};
392  const auto &current_section = toppar_map.find(section_name);
393  if (current_section != toppar_map.end()) {
394  success = parse_section(get<1>(current_section->second), toppar_data.Numang,
395  toppar_data.Tk, section_name);
396  get<0>(current_section->second) = true;
397  } else {
398  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
399  }
400  }
401  // ANGLE_EQUIL_VALUE
402  if (success) {
403  const string section_name{"ANGLE_EQUIL_VALUE"};
404  const auto &current_section = toppar_map.find(section_name);
405  if (current_section != toppar_map.end()) {
406  success = parse_section(get<1>(current_section->second), toppar_data.Numang,
407  toppar_data.Teq, section_name);
408  get<0>(current_section->second) = true;
409  } else {
410  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
411  }
412  }
413  // DIHEDRAL_FORCE_CONSTANT
414  if (success) {
415  const string section_name{"DIHEDRAL_FORCE_CONSTANT"};
416  const auto &current_section = toppar_map.find(section_name);
417  if (current_section != toppar_map.end()) {
418  success = parse_section(get<1>(current_section->second), toppar_data.Nptra,
419  toppar_data.Pk, section_name);
420  get<0>(current_section->second) = true;
421  } else {
422  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
423  }
424  }
425  // DIHEDRAL_PERIODICITY
426  if (success) {
427  const string section_name{"DIHEDRAL_PERIODICITY"};
428  const auto &current_section = toppar_map.find(section_name);
429  if (current_section != toppar_map.end()) {
430  success = parse_section(get<1>(current_section->second), toppar_data.Nptra,
431  toppar_data.Pn, section_name);
432  get<0>(current_section->second) = true;
433  } else {
434  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
435  }
436  }
437  // DIHEDRAL_PHASE
438  if (success) {
439  const string section_name{"DIHEDRAL_PHASE"};
440  const auto &current_section = toppar_map.find(section_name);
441  if (current_section != toppar_map.end()) {
442  success = parse_section(get<1>(current_section->second), toppar_data.Nptra,
443  toppar_data.Phase, section_name);
444  get<0>(current_section->second) = true;
445  } else {
446  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
447  }
448  }
449  // SCEE_SCALE_FACTOR
450  if (success) {
451  const string section_name{"SCEE_SCALE_FACTOR"};
452  const auto &current_section = toppar_map.find(section_name);
453  if (current_section != toppar_map.end()) {
454  success = parse_section(get<1>(current_section->second), toppar_data.Nptra,
455  toppar_data.SceeScaleFactor, section_name);
456  get<0>(current_section->second) = true;
457  } else {
458  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
459  }
460  }
461  // SCNB_SCALE_FACTOR
462  if (success) {
463  const string section_name{"SCNB_SCALE_FACTOR"};
464  const auto &current_section = toppar_map.find(section_name);
465  if (current_section != toppar_map.end()) {
466  success = parse_section(get<1>(current_section->second), toppar_data.Nptra,
467  toppar_data.ScnbScaleFactor, section_name);
468  get<0>(current_section->second) = true;
469  } else {
470  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
471  }
472  }
473  // SOLTY (UNUSED)
474  if (success) {
475  const string section_name{"SOLTY"};
476  const auto &current_section = toppar_map.find(section_name);
477  if (current_section != toppar_map.end()) {
478  // success = parse_section(get<1>(current_section->second),
479  // toppar_data.Natyp, toppar_data.Solty,
480  // section_name);
481  get<0>(current_section->second) = true;
482  } else {
483  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
484  }
485  }
486  // LENNARD_JONES_ACOEF
487  if (success) {
488  const int Nttyp = toppar_data.Ntypes * (toppar_data.Ntypes + 1) / 2;
489  const string section_name{"LENNARD_JONES_ACOEF"};
490  const auto &current_section = toppar_map.find(section_name);
491  if (current_section != toppar_map.end()) {
492  success = parse_section(get<1>(current_section->second), Nttyp, toppar_data.Cn1,
493  section_name);
494  get<0>(current_section->second) = true;
495  } else {
496  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
497  }
498  }
499  // LENNARD_JONES_BCOEF
500  if (success) {
501  const int Nttyp = toppar_data.Ntypes * (toppar_data.Ntypes + 1) / 2;
502  const string section_name{"LENNARD_JONES_BCOEF"};
503  const auto &current_section = toppar_map.find(section_name);
504  if (current_section != toppar_map.end()) {
505  success = parse_section(get<1>(current_section->second), Nttyp, toppar_data.Cn2,
506  section_name);
507  get<0>(current_section->second) = true;
508  } else {
509  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
510  }
511  }
512  // BONDS_INC_HYDROGEN
513  if (success) {
514  const string section_name{"BONDS_INC_HYDROGEN"};
515  const auto &current_section = toppar_map.find(section_name);
516  if (current_section != toppar_map.end()) {
517  success = parse_section(get<1>(current_section->second), toppar_data.Nbonh,
518  {ref(toppar_data.BondHAt1), ref(toppar_data.BondHAt2),
519  ref(toppar_data.BondHNum)},
520  section_name);
521  get<0>(current_section->second) = true;
522  } else {
523  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
524  }
525  }
526  // BONDS_WITHOUT_HYDROGEN
527  if (success) {
528  const string section_name{"BONDS_WITHOUT_HYDROGEN"};
529  const auto &current_section = toppar_map.find(section_name);
530  if (current_section != toppar_map.end()) {
531  success = parse_section(get<1>(current_section->second), toppar_data.Nbona,
532  {ref(toppar_data.BondAt1), ref(toppar_data.BondAt2),
533  ref(toppar_data.BondNum)},
534  section_name);
535  get<0>(current_section->second) = true;
536  } else {
537  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
538  }
539  }
540  // ANGLES_INC_HYDROGEN
541  if (success) {
542  const string section_name{"ANGLES_INC_HYDROGEN"};
543  const auto &current_section = toppar_map.find(section_name);
544  if (current_section != toppar_map.end()) {
545  success = parse_section(get<1>(current_section->second), toppar_data.Ntheth,
546  {ref(toppar_data.AngleHAt1), ref(toppar_data.AngleHAt2),
547  ref(toppar_data.AngleHAt3), ref(toppar_data.AngleHNum)},
548  section_name);
549  get<0>(current_section->second) = true;
550  } else {
551  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
552  }
553  }
554  // ANGLES_WITHOUT_HYDROGEN
555  if (success) {
556  const string section_name{"ANGLES_WITHOUT_HYDROGEN"};
557  const auto &current_section = toppar_map.find(section_name);
558  if (current_section != toppar_map.end()) {
559  success = parse_section(get<1>(current_section->second), toppar_data.Ntheta,
560  {ref(toppar_data.AngleAt1), ref(toppar_data.AngleAt2),
561  ref(toppar_data.AngleAt3), ref(toppar_data.AngleNum)},
562  section_name);
563  get<0>(current_section->second) = true;
564  } else {
565  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
566  }
567  }
568  // DIHEDRALS_INC_HYDROGEN
569  if (success) {
570  const string section_name{"DIHEDRALS_INC_HYDROGEN"};
571  const auto &current_section = toppar_map.find(section_name);
572  if (current_section != toppar_map.end()) {
573  success = parse_section(get<1>(current_section->second), toppar_data.Nphih,
574  {ref(toppar_data.DihHAt1), ref(toppar_data.DihHAt2),
575  ref(toppar_data.DihHAt3), ref(toppar_data.DihHAt4),
576  ref(toppar_data.DihHNum)},
577  section_name);
578  get<0>(current_section->second) = true;
579  } else {
580  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
581  }
582  }
583  // DIHEDRALS_WITHOUT_HYDROGEN
584  if (success) {
585  const string section_name{"DIHEDRALS_WITHOUT_HYDROGEN"};
586  const auto &current_section = toppar_map.find(section_name);
587  if (current_section != toppar_map.end()) {
588  success = parse_section(get<1>(current_section->second), toppar_data.Nphia,
589  {ref(toppar_data.DihAt1), ref(toppar_data.DihAt2),
590  ref(toppar_data.DihAt3), ref(toppar_data.DihAt4),
591  ref(toppar_data.DihNum)},
592  section_name);
593  get<0>(current_section->second) = true;
594  } else {
595  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
596  }
597  }
598  // EXCLUDED_ATOMS_LIST
599  if (success) {
600  const string section_name{"EXCLUDED_ATOMS_LIST"};
601  const auto &current_section = toppar_map.find(section_name);
602  if (current_section != toppar_map.end()) {
603  success = parse_section(get<1>(current_section->second), toppar_data.Nnb,
604  toppar_data.ExclAt, section_name);
605  get<0>(current_section->second) = true;
606  } else {
607  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
608  }
609  }
610  // HBOND_ACOEF
611  if (success) {
612  const string section_name{"HBOND_ACOEF"};
613  const auto &current_section = toppar_map.find(section_name);
614  if (current_section != toppar_map.end()) {
615  success = parse_section(get<1>(current_section->second), toppar_data.Nphb,
616  toppar_data.HB12, section_name);
617  get<0>(current_section->second) = true;
618  } else {
619  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
620  }
621  }
622  // HBOND_BCOEF
623  if (success) {
624  const string section_name{"HBOND_BCOEF"};
625  const auto &current_section = toppar_map.find(section_name);
626  if (current_section != toppar_map.end()) {
627  success = parse_section(get<1>(current_section->second), toppar_data.Nphb,
628  toppar_data.HB10, section_name);
629  get<0>(current_section->second) = true;
630  } else {
631  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
632  }
633  }
634  // HBCUT (UNUSED)
635  if (success) {
636  const string section_name{"HBCUT"};
637  const auto &current_section = toppar_map.find(section_name);
638  if (current_section != toppar_map.end()) {
639  // skip HBCUT
640  get<0>(current_section->second) = true;
641  } else {
642  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
643  }
644  }
645  // AMBER_ATOM_TYPE
646  if (success) {
647  const string section_name{"AMBER_ATOM_TYPE"};
648  const auto &current_section = toppar_map.find(section_name);
649  if (current_section != toppar_map.end()) {
650  success = parse_section(get<1>(current_section->second), toppar_data.Natom,
651  toppar_data.AtomSym, section_name);
652  get<0>(current_section->second) = true;
653  } else {
654  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
655  }
656  }
657  // TREE_CHAIN_CLASSIFICATION
658  if (success) {
659  const string section_name{"TREE_CHAIN_CLASSIFICATION"};
660  const auto &current_section = toppar_map.find(section_name);
661  if (current_section != toppar_map.end()) {
662  success = parse_section(get<1>(current_section->second), toppar_data.Natom,
663  toppar_data.AtomTree, section_name);
664  get<0>(current_section->second) = true;
665  } else {
666  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
667  }
668  }
669  // JOIN_ARRAY (UNUSED)
670  if (success) {
671  const string section_name{"JOIN_ARRAY"};
672  const auto &current_section = toppar_map.find(section_name);
673  if (current_section != toppar_map.end()) {
674  // success = parse_section(get<1>(current_section->second),
675  // toppar_data.Natom, toppar_data.TreeJoin,
676  // section_name);
677  get<0>(current_section->second) = true;
678  } else {
679  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
680  }
681  }
682  // IROTAT (UNUSED)
683  if (success) {
684  const string section_name{"IROTAT"};
685  const auto &current_section = toppar_map.find(section_name);
686  if (current_section != toppar_map.end()) {
687 // success = parse_section(get<1>(current_section->second),
688 // toppar_data.Natom, toppar_data.IrotatArray,
689 // section_name);
690  get<0>(current_section->second) = true;
691  } else {
692  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
693  }
694  }
695  // parse periodic boundary conditions only if IFBOX > 0
696  if (toppar_data.Ifbox > 0) {
697  // SOLVENT_POINTERS
698  if (success) {
699  const string section_name{"SOLVENT_POINTERS"};
700  const auto &current_section = toppar_map.find(section_name);
701  if (current_section != toppar_map.end()) {
702  if (get<1>(current_section->second).size() == 3) {
703  toppar_data.Iptres = get<1>(current_section->second)[0].Int;
704  toppar_data.Nspm = get<1>(current_section->second)[1].Int;
705  toppar_data.Nspsol = get<1>(current_section->second)[2].Int;
706  toppar_data.AtomsPerMolecule.reserve(toppar_data.Nspm);
707  toppar_data.BoxDimensions.reserve(4);
708  toppar_data.CapInfo.reserve(1);
709  toppar_data.CapInfo2.reserve(4);
710  get<0>(current_section->second) = true;
711  } else {
712  iout << iERROR << "Expect " << 3 << " fields but only "
713  << get<1>(current_section->second).size() << " are in "
714  << section_name.c_str() << "\n";
715  success = false;
716  }
717  } else {
718  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
719  }
720  }
721  // ATOMS_PER_MOLECULE
722  if (success) {
723  const string section_name{"ATOMS_PER_MOLECULE"};
724  const auto &current_section = toppar_map.find(section_name);
725  if (current_section != toppar_map.end()) {
726  success = parse_section(get<1>(current_section->second), toppar_data.Nspm,
727  toppar_data.AtomsPerMolecule, section_name);
728  get<0>(current_section->second) = true;
729  } else {
730  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
731  }
732  }
733  // BOX_DIMENSIONS
734  if (success) {
735  const string section_name{"BOX_DIMENSIONS"};
736  const auto &current_section = toppar_map.find(section_name);
737  if (current_section != toppar_map.end()) {
738  success = parse_section(get<1>(current_section->second), 4,
739  toppar_data.BoxDimensions, section_name);
740  get<0>(current_section->second) = true;
741  } else {
742  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
743  }
744  }
745  }
746  if (toppar_data.Ifcap > 0) {
747  // CAP_INFO
748  if (success) {
749  const string section_name{"CAP_INFO"};
750  const auto &current_section = toppar_map.find(section_name);
751  if (current_section != toppar_map.end()) {
752  success = parse_section(get<1>(current_section->second), 1, toppar_data.CapInfo,
753  section_name);
754  get<0>(current_section->second) = true;
755  } else {
756  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
757  }
758  }
759  // CAP_INFO2
760  if (success) {
761  const string section_name{"CAP_INFO2"};
762  const auto &current_section = toppar_map.find(section_name);
763  if (current_section != toppar_map.end()) {
764  success = parse_section(get<1>(current_section->second), 4, toppar_data.CapInfo2,
765  section_name);
766  get<0>(current_section->second) = true;
767  } else {
768  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
769  }
770  }
771  }
772  // RADIUS_SET
773  if (success) {
774  const string section_name{"RADIUS_SET"};
775  const auto &current_section = toppar_map.find(section_name);
776  if (current_section != toppar_map.end()) {
777  success = parse_section(get<1>(current_section->second), 1, toppar_data.RadiusSet,
778  section_name);
779  get<0>(current_section->second) = true;
780  } else {
781  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
782  }
783  }
784  // RADII
785  if (success) {
786  const string section_name{"RADII"};
787  const auto &current_section = toppar_map.find(section_name);
788  if (current_section != toppar_map.end()) {
789  success = parse_section(get<1>(current_section->second), toppar_data.Natom,
790  toppar_data.Radii, section_name);
791  get<0>(current_section->second) = true;
792  } else {
793  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
794  }
795  }
796  // SCREEN
797  if (success) {
798  const string section_name{"SCREEN"};
799  const auto &current_section = toppar_map.find(section_name);
800  if (current_section != toppar_map.end()) {
801  success = parse_section(get<1>(current_section->second), toppar_data.Natom,
802  toppar_data.Screen, section_name);
803  get<0>(current_section->second) = true;
804  } else {
805  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
806  }
807  }
808  // parse IPOL to determine the polarizability
809  if (success) {
810  const string section_name{"IPOL"};
811  const auto &current_section = toppar_map.find(section_name);
812  if (current_section != toppar_map.end()) {
813  toppar_data.Ipol = get<1>(current_section->second)[0].Int;
814  toppar_data.Polarizability.reserve(toppar_data.Natom);
815  get<0>(current_section->second) = true;
816  } else {
817  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
818  }
819  }
820  if (toppar_data.Ipol > 0) {
821  // POLARIZABILITY
822  if (success) {
823  const string section_name{"POLARIZABILITY"};
824  const auto &current_section = toppar_map.find(section_name);
825  if (current_section != toppar_map.end()) {
826  success = parse_section(get<1>(current_section->second), toppar_data.Natom,
827  toppar_data.Polarizability, section_name);
828  get<0>(current_section->second) = true;
829  } else {
830  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
831  }
832  }
833  }
834  if (toppar_data.IsCharmmFF) {
835  // I don't think supporting CHARMBER is a good idea since we have supported,
836  // CHARMM force field in PSF format, and the user should use PSF instead of
837  // AMBER format.
838  // CHARMM_UREY_BRADLEY_COUNT
839  if (success) {
840  const string section_name{"CHARMM_UREY_BRADLEY_COUNT"};
841  const auto &current_section = toppar_map.find(section_name);
842  if (current_section != toppar_map.end()) {
843  if (get<1>(current_section->second).size() == 2) {
844  toppar_data.Nub = get<1>(current_section->second)[0].Int;
845  toppar_data.Nubtypes = get<1>(current_section->second)[1].Int;
846  toppar_data.UreyBradleyAt1.reserve(toppar_data.Nub);
847  toppar_data.UreyBradleyAt2.reserve(toppar_data.Nub);
848  toppar_data.UreyBradleyNum.reserve(toppar_data.Nub);
849  toppar_data.UreyBradleyForceConstants.reserve(toppar_data.Nubtypes);
850  toppar_data.UreyBradleyEquilValues.reserve(toppar_data.Nubtypes);
851  get<0>(current_section->second) = true;
852  } else {
853  iout << iERROR << "Expect " << 2 << " fields but only "
854  << get<1>(current_section->second).size() << " are in "
855  << section_name.c_str() << "\n";
856  success = false;
857  }
858  } else {
859  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
860  }
861  }
862  // CHARMM_UREY_BRADLEY
863  if (success) {
864  const string section_name{"CHARMM_UREY_BRADLEY"};
865  const auto &current_section = toppar_map.find(section_name);
866  if (current_section != toppar_map.end()) {
867  success = parse_section(get<1>(current_section->second), toppar_data.Nub,
868  {ref(toppar_data.UreyBradleyAt1),
869  ref(toppar_data.UreyBradleyAt2),
870  ref(toppar_data.UreyBradleyNum)},
871  section_name);
872  get<0>(current_section->second) = true;
873  } else {
874  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
875  }
876  }
877  // CHARMM_UREY_BRADLEY_FORCE_CONSTANT
878  if (success) {
879  const string section_name{"CHARMM_UREY_BRADLEY_FORCE_CONSTANT"};
880  const auto &current_section = toppar_map.find(section_name);
881  if (current_section != toppar_map.end()) {
882  success = parse_section(get<1>(current_section->second), toppar_data.Nubtypes,
883  toppar_data.UreyBradleyForceConstants, section_name);
884  get<0>(current_section->second) = true;
885  } else {
886  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
887  }
888  }
889  // CHARMM_UREY_BRADLEY_EQUIL_VALUE
890  if (success) {
891  const string section_name{"CHARMM_UREY_BRADLEY_EQUIL_VALUE"};
892  const auto &current_section = toppar_map.find(section_name);
893  if (current_section != toppar_map.end()) {
894  success = parse_section(get<1>(current_section->second), toppar_data.Nubtypes,
895  toppar_data.UreyBradleyEquilValues, section_name);
896  get<0>(current_section->second) = true;
897  } else {
898  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
899  }
900  }
901  // CHARMM_NUM_IMPROPERS
902  if (success) {
903  const string section_name{"CHARMM_NUM_IMPROPERS"};
904  const auto &current_section = toppar_map.find(section_name);
905  if (current_section != toppar_map.end()) {
906  if (get<1>(current_section->second).size() == 1) {
907  toppar_data.Nimphi = get<1>(current_section->second)[0].Int;
908  toppar_data.ImproperAt1.reserve(toppar_data.Nimphi);
909  toppar_data.ImproperAt2.reserve(toppar_data.Nimphi);
910  toppar_data.ImproperAt3.reserve(toppar_data.Nimphi);
911  toppar_data.ImproperAt4.reserve(toppar_data.Nimphi);
912  toppar_data.ImproperNum.reserve(toppar_data.Nimphi);
913  get<0>(current_section->second) = true;
914  } else {
915  iout << iERROR << "Expect " << 1 << " fields but only "
916  << get<1>(current_section->second).size() << " are in "
917  << section_name.c_str() << "\n";
918  success = false;
919  }
920  } else {
921  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
922  }
923  }
924  // CHARMM_IMPROPERS
925  if (success) {
926  const string section_name{"CHARMM_IMPROPERS"};
927  const auto &current_section = toppar_map.find(section_name);
928  if (current_section != toppar_map.end()) {
929  success = parse_section(
930  get<1>(current_section->second), toppar_data.Nimphi,
931  {ref(toppar_data.ImproperAt1), ref(toppar_data.ImproperAt2),
932  ref(toppar_data.ImproperAt3), ref(toppar_data.ImproperAt4),
933  ref(toppar_data.ImproperNum)},
934  section_name);
935  get<0>(current_section->second) = true;
936  } else {
937  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
938  }
939  }
940  // CHARMM_NUM_IMPR_TYPES
941  // Not "CHARMM_NUM_IMPROPER_TYPES" in the documentation!
942  if (success) {
943  const string section_name{"CHARMM_NUM_IMPR_TYPES"};
944  const auto &current_section = toppar_map.find(section_name);
945  if (current_section != toppar_map.end()) {
946  toppar_data.NimprTypes = get<1>(current_section->second)[0].Int;
947  toppar_data.ImproperForceConstants.reserve(toppar_data.NimprTypes);
948  toppar_data.ImproperPhases.reserve(toppar_data.NimprTypes);
949  get<0>(current_section->second) = true;
950  } else {
951  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
952  }
953  }
954  // CHARMM_IMPROPER_FORCE_CONSTANT
955  if (success) {
956  const string section_name{"CHARMM_IMPROPER_FORCE_CONSTANT"};
957  const auto &current_section = toppar_map.find(section_name);
958  if (current_section != toppar_map.end()) {
959  success = parse_section(get<1>(current_section->second), toppar_data.NimprTypes,
960  toppar_data.ImproperForceConstants, section_name);
961  get<0>(current_section->second) = true;
962  } else {
963  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
964  }
965  }
966  // CHARMM_IMPROPER_PHASE
967  if (success) {
968  const string section_name{"CHARMM_IMPROPER_PHASE"};
969  const auto &current_section = toppar_map.find(section_name);
970  if (current_section != toppar_map.end()) {
971  success = parse_section(get<1>(current_section->second), toppar_data.NimprTypes,
972  toppar_data.ImproperPhases, section_name);
973  get<0>(current_section->second) = true;
974  } else {
975  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
976  }
977  }
978  // LENNARD_JONES_14_ACOEF
979  if (success) {
980  const int Nttyp = toppar_data.Ntypes * (toppar_data.Ntypes + 1) / 2;
981  const string section_name{"LENNARD_JONES_14_ACOEF"};
982  const auto &current_section = toppar_map.find(section_name);
983  if (current_section != toppar_map.end()) {
984  // this is not assigned before
985  toppar_data.LJ14ACoefficients.reserve(Nttyp);
986  success = parse_section(get<1>(current_section->second), Nttyp,
987  toppar_data.LJ14ACoefficients, section_name);
988  get<0>(current_section->second) = true;
989  } else {
990  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
991  }
992  }
993  // LENNARD_JONES_14_BCOEF
994  if (success) {
995  const int Nttyp = toppar_data.Ntypes * (toppar_data.Ntypes + 1) / 2;
996  const string section_name{"LENNARD_JONES_14_BCOEF"};
997  const auto &current_section = toppar_map.find(section_name);
998  if (current_section != toppar_map.end()) {
999  // this is not assigned before
1000  toppar_data.LJ14BCoefficients.reserve(Nttyp);
1001  success = parse_section(get<1>(current_section->second), Nttyp,
1002  toppar_data.LJ14BCoefficients, section_name);
1003  get<0>(current_section->second) = true;
1004  } else {
1005  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
1006  }
1007  }
1008  }
1009  // Trying to parse CMAP terms
1010  // ff19SB also have CMAP terms, so CMAP is not CHARMM-specific.
1011  // However, in CHARMM FF they are prefixed with CHARMM_
1012  // CMAP_COUNT or CHARMM_CMAP_COUNT
1013  if (success) {
1014  const string section_name = toppar_data.IsCharmmFF
1015  ? string("CHARMM_CMAP_COUNT")
1016  : string("CMAP_COUNT");
1017  const auto &current_section = toppar_map.find(section_name);
1018  if (current_section != toppar_map.end()) {
1019  if (get<1>(current_section->second).size() == 2) {
1020  toppar_data.CMAPTermCount = get<1>(current_section->second)[0].Int;
1021  toppar_data.CMAPTypeCount = get<1>(current_section->second)[1].Int;
1022  toppar_data.HasCMAP = true;
1023  toppar_data.CMAPResolution.reserve(toppar_data.CMAPTypeCount);
1024  // CMAPParameter will be resized later after reading CMAPResolution
1025  toppar_data.CMAPParameter.reserve(toppar_data.CMAPTypeCount);
1026  toppar_data.CMAPIndex.reserve(toppar_data.CMAPTermCount * 6);
1027  get<0>(current_section->second) = true;
1028  } else {
1029  iout << iERROR << "Expect " << 2 << " fields but only "
1030  << get<1>(current_section->second).size() << " are in "
1031  << section_name.c_str() << "\n";
1032  success = false;
1033  }
1034  } else {
1035  toppar_data.HasCMAP = false;
1036  }
1037  }
1038  if (toppar_data.HasCMAP) {
1039  // CMAP_RESOLUTION or CHARMM_CMAP_RESOLUTION
1040  if (success) {
1041  const string section_name = toppar_data.IsCharmmFF
1042  ? string("CHARMM_CMAP_RESOLUTION")
1043  : string("CMAP_RESOLUTION");
1044  const auto &current_section = toppar_map.find(section_name);
1045  if (current_section != toppar_map.end()) {
1046  success = parse_section(get<1>(current_section->second),
1047  toppar_data.CMAPTypeCount, toppar_data.CMAPResolution,
1048  section_name);
1049  for (int i = 0; i < toppar_data.CMAPTypeCount; ++i) {
1050  toppar_data.CMAPParameter.push_back(vector<_REAL>());
1051  }
1052  get<0>(current_section->second) = true;
1053  } else {
1054  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
1055  }
1056  }
1057  // CHARMM_CMAP_PARAMETER_N or CMAP_PARAMETER_N
1058  if (success) {
1059  for (int i = 0; i < toppar_data.CMAPTypeCount; ++i) {
1060  string name_index = std::to_string(i + 1);
1061  if (name_index.size() < 2)
1062  name_index.insert(0, "0");
1063  const string section_name =
1064  (toppar_data.IsCharmmFF ? string("CHARMM_CMAP_PARAMETER_")
1065  : string("CMAP_PARAMETER_")) +
1066  name_index;
1067  const auto &current_section = toppar_map.find(section_name);
1068  if (current_section != toppar_map.end()) {
1069  const int resolution =
1070  toppar_data.CMAPResolution[i] * toppar_data.CMAPResolution[i];
1071  toppar_data.CMAPParameter[i].reserve(resolution);
1072  success = parse_section(get<1>(current_section->second), resolution,
1073  toppar_data.CMAPParameter[i], section_name);
1074  get<0>(current_section->second) = true;
1075  } else {
1076  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
1077  }
1078  }
1079  }
1080  // CMAP_INDEX
1081  if (success) {
1082  const string section_name = toppar_data.IsCharmmFF
1083  ? string("CHARMM_CMAP_INDEX")
1084  : string("CMAP_INDEX");
1085  const auto &current_section = toppar_map.find(section_name);
1086  if (current_section != toppar_map.end()) {
1087  success = parse_section(get<1>(current_section->second),
1088  toppar_data.CMAPTermCount * 6, toppar_data.CMAPIndex,
1089  section_name);
1090  get<0>(current_section->second) = true;
1091  } else {
1092  iout << iWARN << "Missing " << section_name.c_str() << " section!\n" << endi;
1093  }
1094  }
1095  }
1096  // NAMD requires the residue IDs for all atoms
1097  // so I need to fill AtomRes here before return
1098  if (success) {
1099  int res = 0;
1100  for (int i = 0; i < toppar_data.Natom; ++i) {
1101  if (i + 1 == toppar_data.Ipres[res+1])
1102  ++res;
1103  toppar_data.AtomRes.push_back(res);
1104  }
1105  }
1106  // now we check and report any unknown sections
1107  for (auto it = toppar_map.begin(); it != toppar_map.end(); ++it) {
1108  if (get<0>(it->second) == false) {
1109  iout << iWARN << "Unknown section " << (it->first).c_str()
1110  << " found in the AMBER format paramter file!\n" << endi;
1111  }
1112  }
1113  return success;
1114 }
_REAL * Pk
Definition: parm.h:24
int * DihHAt1
Definition: parm.h:27
_REAL * Teq
Definition: parm.h:24
char * AtomTree
Definition: parm.h:23
int * BondHNum
Definition: parm.h:27
int * DihAt3
Definition: parm.h:27
char ititl[81]
Definition: parm.h:16
int Natom
Definition: parm.h:17
_REAL * Phase
Definition: parm.h:24
int Nphih
Definition: parm.h:17
int * AngleHNum
Definition: parm.h:27
int Iptres
Definition: parm.h:17
int * BondAt2
Definition: parm.h:27
int Nbonh
Definition: parm.h:17
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
std::ostream & iWARN(std::ostream &s)
Definition: InfoStream.C:82
int * DihHAt4
Definition: parm.h:27
_REAL * Tk
Definition: parm.h:24
#define iout
Definition: InfoStream.h:51
int * Iblo
Definition: parm.h:27
char * ResNames
Definition: parm.h:23
int * DihAt4
Definition: parm.h:27
_REAL * Masses
Definition: parm.h:24
int * AngleHAt1
Definition: parm.h:27
int Numbnd
Definition: parm.h:17
_REAL * HB12
Definition: parm.h:24
int * AngleNum
Definition: parm.h:27
int * DihHNum
Definition: parm.h:27
int * Iac
Definition: parm.h:27
_REAL * Charges
Definition: parm.h:24
int Ntypes
Definition: parm.h:17
int * DihAt1
Definition: parm.h:27
int * BondNum
Definition: parm.h:27
bool parse_pointer(const vector< FortranData > &source, Ambertoppar &result)
int * DihNum
Definition: parm.h:27
int Nbona
Definition: parm.h:17
int * BondHAt1
Definition: parm.h:27
int * AngleHAt3
Definition: parm.h:27
char * AtomNames
Definition: parm.h:23
_REAL * Cn2
Definition: parm.h:24
int * AtomRes
Definition: parm.h:27
int Ntheta
Definition: parm.h:17
int * AngleAt3
Definition: parm.h:27
int * AngleAt1
Definition: parm.h:27
char * AtomSym
Definition: parm.h:23
int * BondAt1
Definition: parm.h:27
int Nspm
Definition: parm.h:17
int Ntheth
Definition: parm.h:17
_REAL * Rk
Definition: parm.h:24
int Nnb
Definition: parm.h:17
int * DihHAt2
Definition: parm.h:27
int Nphb
Definition: parm.h:17
_REAL * Cn1
Definition: parm.h:24
int * DihAt2
Definition: parm.h:27
int Numang
Definition: parm.h:17
_REAL * Req
Definition: parm.h:24
int Nphia
Definition: parm.h:17
int * AngleAt2
Definition: parm.h:27
std::ostream & iERROR(std::ostream &s)
Definition: InfoStream.C:83
int * ExclAt
Definition: parm.h:27
int * AngleHAt2
Definition: parm.h:27
int Nres
Definition: parm.h:17
int * Ipres
Definition: parm.h:27
int Nptra
Definition: parm.h:17
int Nspsol
Definition: parm.h:17
int * BondHAt2
Definition: parm.h:27
int * Cno
Definition: parm.h:27
_REAL * Pn
Definition: parm.h:24
int * DihHAt3
Definition: parm.h:27
bool parse_section(const vector< FortranData > &source, const int &count, vector< string > &destination, const string &section_name)
Copy data from source to destination.
Ambertoppar AmberParm7Reader::readparm ( const char *  filename)

Definition at line 1342 of file ReadAmberParm.C.

References endi(), AmberParm7Reader::Ambertoppar::HasData, iERROR(), iINFO(), iout, NAMD_die(), read_amber_parm_stage1(), and read_amber_parm_stage2().

Referenced by NamdState::loadStructure().

1342  {
1343  AmberParm7Reader::AmberTopparMap Amber_toppar_map;
1345  iout << iINFO << "=== Start reading AMBER parm7 format file " << filename << " ===\n" << endi;
1346  if (AmberParm7Reader::read_amber_parm_stage1(filename, Amber_toppar_map)) {
1347  if (AmberParm7Reader::read_amber_parm_stage2(Amber_toppar_map, data) == true) {
1348  data.HasData = true;
1349  } else {
1350  iout << iERROR << "Failed to read AMBER parm7 file: " << filename << " at read_amber_parm_stage2\n" << endi;
1351  NAMD_die("Error in Ambertoppar readparm(const char *filename)\n");
1352  }
1353  } else {
1354  iout << iERROR << "Failed to read AMBER parm7 file: " << filename << " at read_amber_parm_stage1\n" << endi;
1355  NAMD_die("Error in Ambertoppar readparm(const char *filename)\n");
1356  }
1357  iout << iINFO << "=== Finish reading AMBER parm7 format file. ===\n" << endi;
1358  return data;
1359 }
std::ostream & iINFO(std::ostream &s)
Definition: InfoStream.C:81
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
unordered_map< string, tuple< bool, vector< FortranData > > > AmberTopparMap
Definition: ReadAmberParm.h:87
#define iout
Definition: InfoStream.h:51
bool read_amber_parm_stage2(AmberTopparMap &toppar_map, Ambertoppar &toppar_data)
Read an AmberTopparMap into an Ambertoppar struct for NAMD.
bool read_amber_parm_stage1(const char *filename, AmberTopparMap &toppar_map)
Read an AMBER topology file into an AmberTopparMap.
void NAMD_die(const char *err_msg)
Definition: common.C:85
std::ostream & iERROR(std::ostream &s)
Definition: InfoStream.C:83
void AmberParm7Reader::split_string ( const std::string &  data,
const std::string &  delim,
std::vector< std::string > &  dest 
)

Definition at line 76 of file ReadAmberParm.C.

Referenced by parse_fortran_format().

78  {
79  size_t index = 0, new_index = 0;
80  std::string tmpstr;
81  while (index != data.length()) {
82  new_index = data.find(delim, index);
83  if (new_index != std::string::npos) tmpstr = data.substr(index, new_index - index);
84  else tmpstr = data.substr(index, data.length());
85  if (!tmpstr.empty()) {
86  dest.push_back(tmpstr);
87  }
88  if (new_index == std::string::npos) break;
89  index = new_index + 1;
90  }
91 }
void AmberParm7Reader::split_string_by_specifiers ( const string &  source,
const vector< FortranFormatSpecifier > &  specifiers,
vector< FortranData > &  destination 
)

This function splits a string by a set of fortran format specifiers.

This function splits a string by a set of fortran format specifiers. For example: If the source string is: " 920979 9 920959 19 47 25 85 66 0 0", and there is only one specifier, "10I8" in the specifiers vector, then the vector destination will be APPENDED with [" 920979", " 9", " 920959",...]

Parameters
sourcethe source string.
destinationthe destination container of the splited data.

Definition at line 104 of file ReadAmberParm.C.

Referenced by read_amber_parm_stage1().

106  {
107  size_t start_pos = 0;
108  for (const auto &spec : specifiers) {
109  if (spec.IsPadding == true) {
110  // I should check padding here but I don't know how to handle the it
111  // Anyway, AMBER parm7 doesn't use padding
112  } else {
113  for (int i = 0; i < spec.NumOfFields; ++i) {
114  if (start_pos < source.size()) {
115  const string tmp = source.substr(start_pos, spec.Width);
116  switch (toupper(spec.Type)) {
117  case 'I':
118  destination.push_back(std::stoi(tmp));
119  break;
120  case 'A':
121  destination.push_back(tmp);
122  break;
123  case 'D':
124  case 'E':
125  case 'G':
126  case 'F':
127  // fall through for all floating point specifiers
128 #ifdef DOUBLE
129  destination.push_back(std::stod(tmp));
130 #else
131  destination.push_back(std::stof(tmp));
132 #endif
133  break;
134  }
135  start_pos += spec.Width;
136  }
137  }
138  }
139  }
140 }