25 std::string molkey =
"topology.molecules.molecule";
26 std::vector<tools::Property*> molecules = topology_map.
Select(molkey);
28 throw std::runtime_error(
"Multiple molecules have same mdname");
30 std::string segkey =
"segments.segment";
31 std::vector<tools::Property*> segments_all;
33 std::vector<tools::Property*> segments = mol->Select(segkey);
35 throw std::runtime_error(
"Multiple segments in molecule:" +
36 mol->get(
"mdname").as<std::string>() +
39 segments_all.insert(segments_all.end(), segments.begin(), segments.end());
41 std::string fragkey =
"fragments.fragment";
42 std::vector<tools::Property*> fragments = seg->Select(fragkey);
44 throw std::runtime_error(
45 "Multiple fragments have same name in molecule " +
46 mol->get(
"mdname").as<std::string>() +
" segment " +
47 seg->get(
"name").as<std::string>());
50 std::vector<std::string> atomnames_seg;
52 std::vector<std::string> atomnames =
53 frag->get(
"mdatoms").as<std::vector<std::string>>();
54 atomnames_seg.insert(atomnames_seg.end(), atomnames.begin(),
57 std::sort(atomnames_seg.begin(), atomnames_seg.end());
58 if (adjacent_find(atomnames_seg.begin(), atomnames_seg.end()) !=
59 atomnames_seg.end()) {
60 throw std::runtime_error(
61 "Multiple mdatoms have same identifier in molecule " +
62 mol->get(
"mdname").as<std::string>() +
" segment " +
63 seg->get(
"name").as<std::string>());
68 throw std::runtime_error(
"Multiple segments have same name");
135 std::map<std::string, std::map<Index, std::string>> MolToSegMap;
138 std::map<std::string, std::vector<Index>> MolToAtomIds;
141 std::map<std::string, std::vector<std::string>> SegsinMol;
143 std::string molkey =
"topology.molecules.molecule";
144 std::vector<tools::Property*> molecules = topology_map.
Select(molkey);
145 std::string segkey =
"segments.segment";
149 std::string molname = mol->get(
"mdname").as<std::string>();
151 std::vector<tools::Property*> segments = mol->Select(segkey);
152 std::vector<std::string> segnames;
153 std::vector<Index> atomids;
157 std::string segname = seg->get(
"name").as<std::string>();
158 segnames.push_back(segname);
159 std::string fragkey =
"fragments.fragment";
161 std::vector<tools::Property*> fragments = seg->Select(fragkey);
165 std::vector<std::string> atomnames =
166 frag->get(
"mdatoms").as<std::vector<std::string>>();
168 for (
const std::string& atomname : atomnames) {
171 std::vector<std::string> entries = tok_atom_name.
ToVector();
172 if (entries.size() != 3) {
173 throw std::runtime_error(
"Atom entry " + atomname +
174 " is not well formatted");
180 atomid = std::stoi(entries[2]);
181 }
catch (std::invalid_argument&
e) {
182 throw std::runtime_error(
"Atom entry " + atomname +
183 " is not well formatted");
186 std::cout <<
"... ... processing mapping information for atom "
187 << atomname <<
" with ID " << atomid << std::endl;
189 atomids.push_back(atomid);
190 MolToSegMap[molname][atomid] = segname;
194 std::sort(atomids.begin(), atomids.end());
195 MolToAtomIds[molname] = atomids;
196 SegsinMol[molname] = segnames;
209 std::map<Index, std::vector<Index>> bead_bonded_partners;
211 if (interaction->BeadCount() != 2) {
214 Index id1 = interaction->getBeadId(0);
215 Index id2 = interaction->getBeadId(1);
216 bead_bonded_partners[id1].push_back(id2);
217 bead_bonded_partners[id2].push_back(id1);
240 if (bead_bonded_partners.empty()) {
242 <<
"\nWARNING: the MD topology being mapped contains no real bond "
243 "connectivity at all (no bonded interactions were found within "
244 "it) -- this topology reader may only provide atom positions, "
245 "not real, actual bond data. Automatic H-saturation of cut "
246 "segment boundaries (used by e.g. the ipodcoupling calculator) "
247 "will not be able to detect any external bonds at all, and will "
248 "silently do nothing at all, rather than saturating anything -- "
249 "check that the real, actual topology file/reader used here "
250 "genuinely provides real bond data, not just atom positions."
258 const std::vector<std::string> segnames = SegsinMol[mol.getName()];
259 std::vector<Segment>& topology_segments = xtptop.
Segments();
263 std::cout <<
"... Mapping molecule " << mol.getId() <<
", name "
264 << mol.getName() <<
", # of segments " << segnames.size()
265 <<
", atomID offset " << IdOffset << std::endl;
268 for (
const std::string& segname : segnames) {
270 Index segid = topology_segments.size();
276 for (
const csg::Bead* bead : mol.Beads()) {
278 if (segname == MolToSegMap[mol.getName()][bead->getId() - IdOffset]) {
279 Atom atom(bead->getResnr(), bead->getName(), bead->getId(),
294 auto it = bead_bonded_partners.find(bead->getId());
295 if (it != bead_bonded_partners.end()) {
296 for (
Index partner_id : it->second) {
315 partner_mol = &candidate;
319 if (partner_mol ==
nullptr) {
323 partner_mol, MolToAtomIds[partner_mol->
getName()]);
324 std::string partner_segname =
325 MolToSegMap[partner_mol->
getName()]
326 [partner_bead->
getId() - partner_offset];
327 if (partner_segname != segname) {
328 Eigen::Vector3d direction =
329 (partner_bead->
getPos() - bead->getPos()) *
349 if (it != bead_bonded_partners.end()) {
350 for (
Index partner_id : it->second) {
359 topology_segments.push_back(this_segment);
383 std::map<Index, Index> md_atom_id_to_segment_id;
385 for (
const Atom& segatom : seg) {
386 md_atom_id_to_segment_id[segatom.getId()] = seg.getId();
390 for (
Atom& segatom : seg) {
391 if (!segatom.hasExternalBond()) {
395 md_atom_id_to_segment_id.find(segatom.getExternalBondPartnerAtomId());
396 if (it != md_atom_id_to_segment_id.end()) {
397 segatom.setExternalBondPartnerSegmentId(it->second);