18 size_t left_quotation_mark = str.find(
"'");
19 if (left_quotation_mark == std::string::npos) {
20 std::string num_fields, type, width, dot, precision;
21 for (
size_t i = 0; i < str.size(); ++i) {
23 if (std::isdigit(str[i])) {
25 if (type.size() > 0) {
39 }
else if (std::isalpha(str[i])) {
42 }
else if (str[i] ==
'.') {
50 if (num_fields.size() > 0) {
51 specifier.
NumOfFields = std::stoul(num_fields.c_str());
57 specifier.
Type = type.front();
59 specifier.
Width = std::stoul(width.c_str());
60 if (precision.size() > 0) {
61 specifier.
Precision = std::stoul(precision.c_str());
67 size_t right_quotation_mark = str.find(
"'", left_quotation_mark + 1);
70 str.substr(left_quotation_mark + 1,
71 right_quotation_mark - (left_quotation_mark + 1));
78 const std::string& delim,
79 std::vector<std::string>& dest) {
80 size_t index = 0, new_index = 0;
82 while (index != data.length()) {
83 new_index = data.find(delim, index);
84 if (new_index != std::string::npos) tmpstr = data.substr(index, new_index - index);
85 else tmpstr = data.substr(index, data.length());
86 if (!tmpstr.empty()) {
87 dest.push_back(tmpstr);
89 if (new_index == std::string::npos)
break;
90 index = new_index + 1;
95 vector<FortranFormatSpecifier> &specifiers) {
97 vector<string> sub_format_strings;
99 specifiers.resize(sub_format_strings.size());
100 for (
size_t i = 0; i < sub_format_strings.size(); ++i) {
106 const string &source,
const vector<FortranFormatSpecifier> &specifiers,
107 vector<FortranData> &destination) {
108 size_t start_pos = 0;
109 for (
const auto &spec : specifiers) {
110 if (spec.IsPadding ==
true) {
114 for (
int i = 0; i < spec.NumOfFields; ++i) {
115 if (start_pos < source.size()) {
116 const string tmp = source.substr(start_pos, spec.Width);
118 switch (toupper(spec.Type)) {
120 destination.push_back(std::stoi(tmp));
123 destination.push_back(tmp);
131 destination.push_back(std::stod(tmp));
133 destination.push_back(std::stof(tmp));
137 start_pos += spec.Width;
139 std::cerr <<
"Error on parsing field \"" << tmp
140 <<
"\" with specifier " << spec.Type << std::endl;
151 using std::istringstream;
155 ifstream ifs_parm(filename);
156 if (!ifs_parm.is_open())
return false;
159 bool match_flag =
false;
160 bool match_format =
false;
162 vector<FortranFormatSpecifier> specifiers;
163 tuple<bool, vector<FortranData>> *p_map =
nullptr;
166 while (std::getline(ifs_parm, line)) {
169 line.erase(std::remove(line.begin(), line.end(),
'\r'), line.end());
175 if (line[0] ==
'%') {
176 if (line.find(
"%COMMENT") == 0) {
178 }
else if (line.find(
"%VERSION") == 0) {
180 char tmp_version_stamp[16];
183 if (sscanf(line.c_str(),
"%%VERSION VERSION_STAMP = %9s DATE = %8s %8s",
184 tmp_version_stamp, tmp_date, tmp_time) == 3) {
189 }
else if (line.find(
"%FLAG") == 0) {
191 if (match_flag && match_format) {
193 current_flag.clear();
196 match_format =
false;
198 istringstream iss(line.substr(strlen(
"%FLAG")));
200 p_map = &(toppar_map[current_flag]);
201 std::get<0>(*p_map) =
false;
204 }
else if (line.find(
"%FORMAT") == 0) {
206 if (match_flag ==
false) {
210 const size_t format_start = line.find(
"(", strlen(
"%FORMAT"));
211 const size_t format_end = line.find(
")", format_start + 1);
213 line.substr(format_start + 1, format_end - (format_start + 1)),
220 if (match_flag && match_format) {
225 const std::string error_msg =
226 "Error on parsing AMBER parameter file at section " +
227 current_flag +
", line " + std::to_string(line_no) +
":\"" + line +
"\"\n";
244 auto current_section = toppar_map.find(
"TITLE");
245 if (current_section == toppar_map.end()) {
247 current_section = toppar_map.find(
"CTITLE");
248 if (current_section == toppar_map.end()) {
249 iout <<
iERROR <<
"TITLE/CTITLE section for AMBER/CHARMM force field is not " 255 iout <<
iWARN <<
"You are using CHARMM force field in AMBER format, which is not supported in NAMD!\n" <<
endi;
261 toppar_data.
ititl = get<1>(current_section->second).size() > 0 ? get<1>(current_section->second)[0].String :
string();
262 get<0>(current_section->second) =
true;
266 const string section_name{
"POINTERS"};
267 const auto ¤t_section = toppar_map.find(section_name);
268 if (current_section != toppar_map.end()) {
269 success =
parse_pointer(get<1>(current_section->second), toppar_data);
270 get<0>(current_section->second) =
true;
272 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
277 const string section_name{
"ATOM_NAME"};
278 const auto ¤t_section = toppar_map.find(section_name);
279 if (current_section != toppar_map.end()) {
282 get<0>(current_section->second) =
true;
284 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
289 const string section_name{
"CHARGE"};
290 const auto ¤t_section = toppar_map.find(section_name);
291 if (current_section != toppar_map.end()) {
293 toppar_data.
Charges, section_name);
294 get<0>(current_section->second) =
true;
296 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
301 const string section_name{
"ATOMIC_NUMBER"};
302 const auto ¤t_section = toppar_map.find(section_name);
303 if (current_section != toppar_map.end()) {
306 get<0>(current_section->second) =
true;
308 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
313 const string section_name{
"MASS"};
314 const auto ¤t_section = toppar_map.find(section_name);
315 if (current_section != toppar_map.end()) {
317 toppar_data.
Masses, section_name);
318 get<0>(current_section->second) =
true;
320 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
325 const string section_name{
"ATOM_TYPE_INDEX"};
326 const auto ¤t_section = toppar_map.find(section_name);
327 if (current_section != toppar_map.end()) {
329 toppar_data.
Iac, section_name);
330 get<0>(current_section->second) =
true;
332 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
337 const string section_name{
"NUMBER_EXCLUDED_ATOMS"};
338 const auto ¤t_section = toppar_map.find(section_name);
339 if (current_section != toppar_map.end()) {
341 toppar_data.
Iblo, section_name);
342 get<0>(current_section->second) =
true;
344 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
349 const int Ntype2d = toppar_data.
Ntypes * toppar_data.
Ntypes;
350 const string section_name{
"NONBONDED_PARM_INDEX"};
351 const auto ¤t_section = toppar_map.find(section_name);
352 if (current_section != toppar_map.end()) {
353 success =
parse_section(get<1>(current_section->second), Ntype2d, toppar_data.
Cno,
355 get<0>(current_section->second) =
true;
357 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
362 const string section_name{
"RESIDUE_LABEL"};
363 const auto ¤t_section = toppar_map.find(section_name);
364 if (current_section != toppar_map.end()) {
366 toppar_data.
ResNames, section_name);
367 get<0>(current_section->second) =
true;
369 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
374 const string section_name{
"RESIDUE_POINTER"};
375 const auto ¤t_section = toppar_map.find(section_name);
376 if (current_section != toppar_map.end()) {
378 toppar_data.
Ipres, section_name);
379 get<0>(current_section->second) =
true;
381 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
386 const string section_name{
"BOND_FORCE_CONSTANT"};
387 const auto ¤t_section = toppar_map.find(section_name);
388 if (current_section != toppar_map.end()) {
390 toppar_data.
Rk, section_name);
391 get<0>(current_section->second) =
true;
393 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
398 const string section_name{
"BOND_EQUIL_VALUE"};
399 const auto ¤t_section = toppar_map.find(section_name);
400 if (current_section != toppar_map.end()) {
402 toppar_data.
Req, section_name);
403 get<0>(current_section->second) =
true;
405 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
410 const string section_name{
"ANGLE_FORCE_CONSTANT"};
411 const auto ¤t_section = toppar_map.find(section_name);
412 if (current_section != toppar_map.end()) {
414 toppar_data.
Tk, section_name);
415 get<0>(current_section->second) =
true;
417 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
422 const string section_name{
"ANGLE_EQUIL_VALUE"};
423 const auto ¤t_section = toppar_map.find(section_name);
424 if (current_section != toppar_map.end()) {
426 toppar_data.
Teq, section_name);
427 get<0>(current_section->second) =
true;
429 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
434 const string section_name{
"DIHEDRAL_FORCE_CONSTANT"};
435 const auto ¤t_section = toppar_map.find(section_name);
436 if (current_section != toppar_map.end()) {
438 toppar_data.
Pk, section_name);
439 get<0>(current_section->second) =
true;
441 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
446 const string section_name{
"DIHEDRAL_PERIODICITY"};
447 const auto ¤t_section = toppar_map.find(section_name);
448 if (current_section != toppar_map.end()) {
450 toppar_data.
Pn, section_name);
451 get<0>(current_section->second) =
true;
453 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
458 const string section_name{
"DIHEDRAL_PHASE"};
459 const auto ¤t_section = toppar_map.find(section_name);
460 if (current_section != toppar_map.end()) {
462 toppar_data.
Phase, section_name);
463 get<0>(current_section->second) =
true;
465 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
470 const string section_name{
"SCEE_SCALE_FACTOR"};
471 const auto ¤t_section = toppar_map.find(section_name);
472 if (current_section != toppar_map.end()) {
475 get<0>(current_section->second) =
true;
477 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
482 const string section_name{
"SCNB_SCALE_FACTOR"};
483 const auto ¤t_section = toppar_map.find(section_name);
484 if (current_section != toppar_map.end()) {
487 get<0>(current_section->second) =
true;
489 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
494 const string section_name{
"SOLTY"};
495 const auto ¤t_section = toppar_map.find(section_name);
496 if (current_section != toppar_map.end()) {
500 get<0>(current_section->second) =
true;
502 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
507 const int Nttyp = toppar_data.
Ntypes * (toppar_data.
Ntypes + 1) / 2;
508 const string section_name{
"LENNARD_JONES_ACOEF"};
509 const auto ¤t_section = toppar_map.find(section_name);
510 if (current_section != toppar_map.end()) {
511 success =
parse_section(get<1>(current_section->second), Nttyp, toppar_data.
Cn1,
513 get<0>(current_section->second) =
true;
515 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
520 const int Nttyp = toppar_data.
Ntypes * (toppar_data.
Ntypes + 1) / 2;
521 const string section_name{
"LENNARD_JONES_BCOEF"};
522 const auto ¤t_section = toppar_map.find(section_name);
523 if (current_section != toppar_map.end()) {
524 success =
parse_section(get<1>(current_section->second), Nttyp, toppar_data.
Cn2,
526 get<0>(current_section->second) =
true;
528 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
533 const string section_name{
"BONDS_INC_HYDROGEN"};
534 const auto ¤t_section = toppar_map.find(section_name);
535 if (current_section != toppar_map.end()) {
537 {ref(toppar_data.BondHAt1), ref(toppar_data.BondHAt2),
538 ref(toppar_data.BondHNum)},
540 get<0>(current_section->second) =
true;
542 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
547 const string section_name{
"BONDS_WITHOUT_HYDROGEN"};
548 const auto ¤t_section = toppar_map.find(section_name);
549 if (current_section != toppar_map.end()) {
551 {ref(toppar_data.BondAt1), ref(toppar_data.BondAt2),
552 ref(toppar_data.BondNum)},
554 get<0>(current_section->second) =
true;
556 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
561 const string section_name{
"ANGLES_INC_HYDROGEN"};
562 const auto ¤t_section = toppar_map.find(section_name);
563 if (current_section != toppar_map.end()) {
565 {ref(toppar_data.AngleHAt1), ref(toppar_data.AngleHAt2),
566 ref(toppar_data.AngleHAt3), ref(toppar_data.AngleHNum)},
568 get<0>(current_section->second) =
true;
570 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
575 const string section_name{
"ANGLES_WITHOUT_HYDROGEN"};
576 const auto ¤t_section = toppar_map.find(section_name);
577 if (current_section != toppar_map.end()) {
579 {ref(toppar_data.AngleAt1), ref(toppar_data.AngleAt2),
580 ref(toppar_data.AngleAt3), ref(toppar_data.AngleNum)},
582 get<0>(current_section->second) =
true;
584 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
589 const string section_name{
"DIHEDRALS_INC_HYDROGEN"};
590 const auto ¤t_section = toppar_map.find(section_name);
591 if (current_section != toppar_map.end()) {
593 {ref(toppar_data.DihHAt1), ref(toppar_data.DihHAt2),
594 ref(toppar_data.DihHAt3), ref(toppar_data.DihHAt4),
595 ref(toppar_data.DihHNum)},
597 get<0>(current_section->second) =
true;
599 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
604 const string section_name{
"DIHEDRALS_WITHOUT_HYDROGEN"};
605 const auto ¤t_section = toppar_map.find(section_name);
606 if (current_section != toppar_map.end()) {
608 {ref(toppar_data.DihAt1), ref(toppar_data.DihAt2),
609 ref(toppar_data.DihAt3), ref(toppar_data.DihAt4),
610 ref(toppar_data.DihNum)},
612 get<0>(current_section->second) =
true;
614 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
619 const string section_name{
"EXCLUDED_ATOMS_LIST"};
620 const auto ¤t_section = toppar_map.find(section_name);
621 if (current_section != toppar_map.end()) {
623 toppar_data.
ExclAt, section_name);
624 get<0>(current_section->second) =
true;
626 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
631 const string section_name{
"HBOND_ACOEF"};
632 const auto ¤t_section = toppar_map.find(section_name);
633 if (current_section != toppar_map.end()) {
635 toppar_data.
HB12, section_name);
636 get<0>(current_section->second) =
true;
638 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
643 const string section_name{
"HBOND_BCOEF"};
644 const auto ¤t_section = toppar_map.find(section_name);
645 if (current_section != toppar_map.end()) {
647 toppar_data.
HB10, section_name);
648 get<0>(current_section->second) =
true;
650 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
655 const string section_name{
"HBCUT"};
656 const auto ¤t_section = toppar_map.find(section_name);
657 if (current_section != toppar_map.end()) {
659 get<0>(current_section->second) =
true;
661 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
666 const string section_name{
"AMBER_ATOM_TYPE"};
667 const auto ¤t_section = toppar_map.find(section_name);
668 if (current_section != toppar_map.end()) {
670 toppar_data.
AtomSym, section_name);
671 get<0>(current_section->second) =
true;
673 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
678 const string section_name{
"TREE_CHAIN_CLASSIFICATION"};
679 const auto ¤t_section = toppar_map.find(section_name);
680 if (current_section != toppar_map.end()) {
682 toppar_data.
AtomTree, section_name);
683 get<0>(current_section->second) =
true;
685 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
690 const string section_name{
"JOIN_ARRAY"};
691 const auto ¤t_section = toppar_map.find(section_name);
692 if (current_section != toppar_map.end()) {
696 get<0>(current_section->second) =
true;
698 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
703 const string section_name{
"IROTAT"};
704 const auto ¤t_section = toppar_map.find(section_name);
705 if (current_section != toppar_map.end()) {
709 get<0>(current_section->second) =
true;
711 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
715 if (toppar_data.
Ifbox > 0) {
718 const string section_name{
"SOLVENT_POINTERS"};
719 const auto ¤t_section = toppar_map.find(section_name);
720 if (current_section != toppar_map.end()) {
721 if (get<1>(current_section->second).size() == 3) {
722 toppar_data.
Iptres = get<1>(current_section->second)[0].Int;
723 toppar_data.
Nspm = get<1>(current_section->second)[1].Int;
724 toppar_data.
Nspsol = get<1>(current_section->second)[2].Int;
727 toppar_data.
CapInfo.reserve(1);
729 get<0>(current_section->second) =
true;
731 iout <<
iERROR <<
"Expect " << 3 <<
" fields but only " 732 << get<1>(current_section->second).size() <<
" are in " 733 << section_name.c_str() <<
"\n";
737 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
742 const string section_name{
"ATOMS_PER_MOLECULE"};
743 const auto ¤t_section = toppar_map.find(section_name);
744 if (current_section != toppar_map.end()) {
747 get<0>(current_section->second) =
true;
749 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
754 const string section_name{
"BOX_DIMENSIONS"};
755 const auto ¤t_section = toppar_map.find(section_name);
756 if (current_section != toppar_map.end()) {
759 get<0>(current_section->second) =
true;
761 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
765 if (toppar_data.
Ifcap > 0) {
768 const string section_name{
"CAP_INFO"};
769 const auto ¤t_section = toppar_map.find(section_name);
770 if (current_section != toppar_map.end()) {
773 get<0>(current_section->second) =
true;
775 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
780 const string section_name{
"CAP_INFO2"};
781 const auto ¤t_section = toppar_map.find(section_name);
782 if (current_section != toppar_map.end()) {
785 get<0>(current_section->second) =
true;
787 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
793 const string section_name{
"RADIUS_SET"};
794 const auto ¤t_section = toppar_map.find(section_name);
795 if (current_section != toppar_map.end()) {
798 get<0>(current_section->second) =
true;
800 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
805 const string section_name{
"RADII"};
806 const auto ¤t_section = toppar_map.find(section_name);
807 if (current_section != toppar_map.end()) {
809 toppar_data.
Radii, section_name);
810 get<0>(current_section->second) =
true;
812 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
817 const string section_name{
"SCREEN"};
818 const auto ¤t_section = toppar_map.find(section_name);
819 if (current_section != toppar_map.end()) {
821 toppar_data.
Screen, section_name);
822 get<0>(current_section->second) =
true;
824 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
829 const string section_name{
"IPOL"};
830 const auto ¤t_section = toppar_map.find(section_name);
831 if (current_section != toppar_map.end()) {
832 toppar_data.
Ipol = get<1>(current_section->second)[0].Int;
834 get<0>(current_section->second) =
true;
836 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
839 if (toppar_data.
Ipol > 0) {
842 const string section_name{
"POLARIZABILITY"};
843 const auto ¤t_section = toppar_map.find(section_name);
844 if (current_section != toppar_map.end()) {
847 get<0>(current_section->second) =
true;
849 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
859 const string section_name{
"CHARMM_UREY_BRADLEY_COUNT"};
860 const auto ¤t_section = toppar_map.find(section_name);
861 if (current_section != toppar_map.end()) {
862 if (get<1>(current_section->second).size() == 2) {
863 toppar_data.
Nub = get<1>(current_section->second)[0].Int;
864 toppar_data.
Nubtypes = get<1>(current_section->second)[1].Int;
870 get<0>(current_section->second) =
true;
872 iout <<
iERROR <<
"Expect " << 2 <<
" fields but only " 873 << get<1>(current_section->second).size() <<
" are in " 874 << section_name.c_str() <<
"\n";
878 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
883 const string section_name{
"CHARMM_UREY_BRADLEY"};
884 const auto ¤t_section = toppar_map.find(section_name);
885 if (current_section != toppar_map.end()) {
887 {ref(toppar_data.UreyBradleyAt1),
888 ref(toppar_data.UreyBradleyAt2),
889 ref(toppar_data.UreyBradleyNum)},
891 get<0>(current_section->second) =
true;
893 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
898 const string section_name{
"CHARMM_UREY_BRADLEY_FORCE_CONSTANT"};
899 const auto ¤t_section = toppar_map.find(section_name);
900 if (current_section != toppar_map.end()) {
903 get<0>(current_section->second) =
true;
905 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
910 const string section_name{
"CHARMM_UREY_BRADLEY_EQUIL_VALUE"};
911 const auto ¤t_section = toppar_map.find(section_name);
912 if (current_section != toppar_map.end()) {
915 get<0>(current_section->second) =
true;
917 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
922 const string section_name{
"CHARMM_NUM_IMPROPERS"};
923 const auto ¤t_section = toppar_map.find(section_name);
924 if (current_section != toppar_map.end()) {
925 if (get<1>(current_section->second).size() == 1) {
926 toppar_data.
Nimphi = get<1>(current_section->second)[0].Int;
932 get<0>(current_section->second) =
true;
934 iout <<
iERROR <<
"Expect " << 1 <<
" fields but only " 935 << get<1>(current_section->second).size() <<
" are in " 936 << section_name.c_str() <<
"\n";
940 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
945 const string section_name{
"CHARMM_IMPROPERS"};
946 const auto ¤t_section = toppar_map.find(section_name);
947 if (current_section != toppar_map.end()) {
949 get<1>(current_section->second), toppar_data.
Nimphi,
950 {ref(toppar_data.ImproperAt1), ref(toppar_data.ImproperAt2),
951 ref(toppar_data.ImproperAt3), ref(toppar_data.ImproperAt4),
952 ref(toppar_data.ImproperNum)},
954 get<0>(current_section->second) =
true;
956 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
962 const string section_name{
"CHARMM_NUM_IMPR_TYPES"};
963 const auto ¤t_section = toppar_map.find(section_name);
964 if (current_section != toppar_map.end()) {
965 toppar_data.
NimprTypes = get<1>(current_section->second)[0].Int;
968 get<0>(current_section->second) =
true;
970 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
975 const string section_name{
"CHARMM_IMPROPER_FORCE_CONSTANT"};
976 const auto ¤t_section = toppar_map.find(section_name);
977 if (current_section != toppar_map.end()) {
980 get<0>(current_section->second) =
true;
982 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
987 const string section_name{
"CHARMM_IMPROPER_PHASE"};
988 const auto ¤t_section = toppar_map.find(section_name);
989 if (current_section != toppar_map.end()) {
992 get<0>(current_section->second) =
true;
994 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
999 const int Nttyp = toppar_data.
Ntypes * (toppar_data.
Ntypes + 1) / 2;
1000 const string section_name{
"LENNARD_JONES_14_ACOEF"};
1001 const auto ¤t_section = toppar_map.find(section_name);
1002 if (current_section != toppar_map.end()) {
1005 success =
parse_section(get<1>(current_section->second), Nttyp,
1007 get<0>(current_section->second) =
true;
1009 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
1014 const int Nttyp = toppar_data.
Ntypes * (toppar_data.
Ntypes + 1) / 2;
1015 const string section_name{
"LENNARD_JONES_14_BCOEF"};
1016 const auto ¤t_section = toppar_map.find(section_name);
1017 if (current_section != toppar_map.end()) {
1020 success =
parse_section(get<1>(current_section->second), Nttyp,
1022 get<0>(current_section->second) =
true;
1024 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
1033 const string section_name = toppar_data.
IsCharmmFF 1034 ? string(
"CHARMM_CMAP_COUNT")
1035 : string(
"CMAP_COUNT");
1036 const auto ¤t_section = toppar_map.find(section_name);
1037 if (current_section != toppar_map.end()) {
1038 if (get<1>(current_section->second).size() == 2) {
1039 toppar_data.
CMAPTermCount = get<1>(current_section->second)[0].Int;
1040 toppar_data.
CMAPTypeCount = get<1>(current_section->second)[1].Int;
1046 get<0>(current_section->second) =
true;
1048 iout <<
iERROR <<
"Expect " << 2 <<
" fields but only " 1049 << get<1>(current_section->second).size() <<
" are in " 1050 << section_name.c_str() <<
"\n";
1060 const string section_name = toppar_data.
IsCharmmFF 1061 ? string(
"CHARMM_CMAP_RESOLUTION")
1062 : string(
"CMAP_RESOLUTION");
1063 const auto ¤t_section = toppar_map.find(section_name);
1064 if (current_section != toppar_map.end()) {
1071 get<0>(current_section->second) =
true;
1073 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
1079 string name_index = std::to_string(i + 1);
1080 if (name_index.size() < 2)
1081 name_index.insert(0,
"0");
1082 const string section_name =
1083 (toppar_data.
IsCharmmFF ? string(
"CHARMM_CMAP_PARAMETER_")
1084 : string(
"CMAP_PARAMETER_")) +
1086 const auto ¤t_section = toppar_map.find(section_name);
1087 if (current_section != toppar_map.end()) {
1088 const int resolution =
1091 success =
parse_section(get<1>(current_section->second), resolution,
1093 get<0>(current_section->second) =
true;
1095 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
1101 const string section_name = toppar_data.
IsCharmmFF 1102 ? string(
"CHARMM_CMAP_INDEX")
1103 : string(
"CMAP_INDEX");
1104 const auto ¤t_section = toppar_map.find(section_name);
1105 if (current_section != toppar_map.end()) {
1109 get<0>(current_section->second) =
true;
1111 iout <<
iWARN <<
"Missing " << section_name.c_str() <<
" section!\n" <<
endi;
1119 for (
int i = 0; i < toppar_data.
Natom; ++i) {
1120 if ((res+1 < toppar_data.
Nres) && (i + 1 == toppar_data.
Ipres[res+1]))
1122 toppar_data.
AtomRes.push_back(res);
1126 for (
auto it = toppar_map.begin(); it != toppar_map.end(); ++it) {
1127 if (get<0>(it->second) ==
false) {
1128 iout <<
iWARN <<
"Unknown section " << (it->first).c_str()
1129 <<
" found in the AMBER format paramter file!\n" <<
endi;
1136 bool success =
true;
1137 if (source.size() > 30) {
1138 result.
Natom = source[0].Int;
1139 result.
Ntypes = source[1].Int;
1140 result.
Nbonh = source[2].Int;
1141 result.
Mbona = source[3].Int;
1142 result.
Ntheth = source[4].Int;
1143 result.
Mtheta = source[5].Int;
1144 result.
Nphih = source[6].Int;
1145 result.
Mphia = source[7].Int;
1146 result.
Nhparm = source[8].Int;
1147 result.
Nparm = source[9].Int;
1148 result.
Nnb = source[10].Int;
1149 result.
Nres = source[11].Int;
1150 result.
Nbona = source[12].Int;
1151 result.
Ntheta = source[13].Int;
1152 result.
Nphia = source[14].Int;
1153 result.
Numbnd = source[15].Int;
1154 result.
Numang = source[16].Int;
1155 result.
Nptra = source[17].Int;
1156 result.
Natyp = source[18].Int;
1157 result.
Nphb = source[19].Int;
1158 result.
Ifpert = source[20].Int;
1159 result.
Nbper = source[21].Int;
1160 result.
Ngper = source[22].Int;
1161 result.
Ndper = source[23].Int;
1162 result.
Mbper = source[24].Int;
1163 result.
Mgper = source[25].Int;
1164 result.
Mdper = source[26].Int;
1165 result.
Ifbox = source[27].Int;
1166 result.
Nmxrs = source[28].Int;
1167 result.
Ifcap = source[29].Int;
1170 result.
Ncopy = 31 < source.size() ? source[31].Int : 0;
1173 const int Nttyp = result.
Ntypes * (result.
Ntypes + 1) / 2;
1180 result.
Cno.reserve(Ntype2d);
1187 result.
Pk.reserve(result.
Nptra);
1188 result.
Pn.reserve(result.
Nptra);
1193 result.
Cn1.reserve(Nttyp);
1194 result.
Cn2.reserve(Nttyp);
1236 vector<string> &destination,
const string §ion_name) {
1237 bool success =
true;
1238 if (
int(source.size()) != count) {
1239 iout <<
iERROR <<
"Expect " << count <<
" fields but only " 1240 << source.size() <<
" are in " 1241 << section_name.c_str() <<
"\n";
1244 for (
int i = 0; i < count; ++i) {
1245 destination.push_back(source[i].String);
1247 iout <<
iINFO <<
"Complete reading " << section_name.c_str() <<
" with " << count <<
" fields.\n" <<
endi;
1253 vector<int> &destination,
const string §ion_name) {
1254 bool success =
true;
1255 if (
int(source.size()) != count) {
1256 iout <<
iERROR <<
"Expect " << count <<
" fields but only " 1257 << source.size() <<
" are in " 1258 << section_name.c_str() <<
"\n";
1261 for (
int i = 0; i < count; ++i) {
1262 destination.push_back(source[i].Int);
1264 iout <<
iINFO <<
"Complete reading " << section_name.c_str() <<
" with " << count <<
" fields.\n" <<
endi;
1270 vector<_REAL> &destination,
const string §ion_name) {
1271 bool success =
true;
1272 if (
int(source.size()) != count) {
1273 iout <<
iERROR <<
"Expect " << count <<
" fields but only " 1274 << source.size() <<
" are in " 1275 << section_name.c_str() <<
"\n";
1278 for (
int i = 0; i < count; ++i) {
1279 destination.push_back(source[i].
Real);
1281 iout <<
iINFO <<
"Complete reading " << section_name.c_str() <<
" with " << count <<
" fields.\n" <<
endi;
1287 const vector<FortranData> &source,
const int &count,
1288 std::initializer_list<std::reference_wrapper<vector<string>>> destination,
1289 const string §ion_name) {
1290 bool success =
true;
1291 const int total_size = destination.size() * count;
1292 if (
int(source.size()) != total_size) {
1293 iout <<
iERROR <<
"Expect " << total_size <<
" fields but only " 1294 << source.size() <<
" are in " 1295 << section_name.c_str() <<
"\n";
1298 const int stride = destination.size();
1299 for (
int i = 0; i < count; ++i) {
1301 for (
auto it_j = destination.begin(); it_j != destination.end(); ++it_j) {
1302 it_j->get().push_back(source[stride * i + j].String);
1306 iout <<
iINFO <<
"Complete reading " << section_name.c_str() <<
" with " << total_size <<
" fields.\n" <<
endi;
1312 const vector<FortranData> &source,
const int &count,
1313 std::initializer_list<std::reference_wrapper<vector<int>>> destination,
1314 const string §ion_name) {
1315 bool success =
true;
1316 const int total_size = destination.size() * count;
1317 if (
int(source.size()) != total_size) {
1318 iout <<
iERROR <<
"Expect " << total_size <<
" fields but only " 1319 << source.size() <<
" are in " 1320 << section_name.c_str() <<
"\n";
1323 const int stride = destination.size();
1324 for (
int i = 0; i < count; ++i) {
1326 for (
auto it_j = destination.begin(); it_j != destination.end(); ++it_j) {
1327 it_j->get().push_back(source[stride * i + j].Int);
1331 iout <<
iINFO <<
"Complete reading " << section_name.c_str() <<
" with " << total_size <<
" fields.\n" <<
endi;
1337 const vector<FortranData> &source,
const int &count,
1338 std::initializer_list<std::reference_wrapper<vector<_REAL>>> destination,
1339 const string §ion_name) {
1340 bool success =
true;
1341 const int total_size = destination.size() * count;
1342 if (
int(source.size()) != total_size) {
1343 iout <<
iERROR <<
"Expect " << total_size <<
" fields but only " 1344 << source.size() <<
" are in " 1345 << section_name.c_str() <<
"\n";
1348 const int stride = destination.size();
1349 for (
int i = 0; i < count; ++i) {
1351 for (
auto it_j = destination.begin(); it_j != destination.end(); ++it_j) {
1352 it_j->get().push_back(source[stride * i + j].
Real);
1356 iout <<
iINFO <<
"Complete reading " << section_name.c_str() <<
" with " << total_size <<
" fields.\n" <<
endi;
1364 iout <<
iINFO <<
"=== Start reading AMBER parm7 format file " << filename <<
" ===\n" <<
endi;
1369 iout <<
iERROR <<
"Failed to read AMBER parm7 file: " << filename <<
" at read_amber_parm_stage2\n" <<
endi;
1370 NAMD_die(
"Error in Ambertoppar readparm(const char *filename)\n");
1373 iout <<
iERROR <<
"Failed to read AMBER parm7 file: " << filename <<
" at read_amber_parm_stage1\n" <<
endi;
1374 NAMD_die(
"Error in Ambertoppar readparm(const char *filename)\n");
1376 iout <<
iINFO <<
"=== Finish reading AMBER parm7 format file. ===\n" <<
endi;
vector< string > RadiusSet
vector< int > UreyBradleyAt2
std::ostream & iINFO(std::ostream &s)
vector< _REAL > BoxDimensions
vector< int > ImproperAt1
void NAMD_err(const char *err_msg)
vector< string > ResNames
vector< string > AtomTree
vector< _REAL > ScnbScaleFactor
vector< int > ImproperAt2
vector< _REAL > Polarizability
std::ostream & endi(std::ostream &s)
unordered_map< string, tuple< bool, vector< FortranData > > > AmberTopparMap
std::ostream & iWARN(std::ostream &s)
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.
vector< int > AtomNumbers
vector< _REAL > ImproperPhases
bool read_amber_parm_stage2(AmberTopparMap &toppar_map, Ambertoppar &toppar_data)
Read an AmberTopparMap into an Ambertoppar struct for NAMD.
vector< int > UreyBradleyAt1
void parse_fortran_format(const std::string &str, FortranFormatSpecifier &specifier)
Parse a single fortran format specifier.
vector< int > CMAPResolution
bool read_amber_parm_stage1(const char *filename, AmberTopparMap &toppar_map)
Read an AMBER topology file into an AmberTopparMap.
bool parse_pointer(const vector< FortranData > &source, Ambertoppar &result)
vector< int > UreyBradleyNum
void split_string(const std::string &data, const std::string &delim, std::vector< std::string > &dest)
vector< _REAL > LJ14BCoefficients
vector< _REAL > LJ14ACoefficients
void NAMD_die(const char *err_msg)
vector< string > AtomNames
vector< vector< _REAL > > CMAPParameter
vector< _REAL > UreyBradleyEquilValues
vector< int > AtomsPerMolecule
vector< int > ImproperNum
Ambertoppar readparm(const char *filename)
vector< int > ImproperAt3
std::ostream & iERROR(std::ostream &s)
vector< _REAL > SceeScaleFactor
vector< _REAL > ImproperForceConstants
vector< _REAL > UreyBradleyForceConstants
bool parse_section(const vector< FortranData > &source, const int &count, vector< string > &destination, const string §ion_name)
Copy data from source to destination.
vector< int > ImproperAt4