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");
142 std::map<std::string, std::map<Index, std::string>> MolToSegMap;
145 std::map<std::string, std::vector<Index>> MolToAtomIds;
148 std::map<std::string, std::vector<std::string>> SegsinMol;
150 std::string molkey =
"topology.molecules.molecule";
151 std::vector<tools::Property*> molecules = topology_map.
Select(molkey);
152 std::string segkey =
"segments.segment";
156 std::string molname = mol->get(
"mdname").as<std::string>();
158 std::vector<tools::Property*> segments = mol->Select(segkey);
159 std::vector<std::string> segnames;
160 std::vector<Index> atomids;
164 std::string segname = seg->get(
"name").as<std::string>();
165 segnames.push_back(segname);
167 std::cout <<
"... ... processing mapping information for segment "
168 << segname << std::endl;
170 std::string fragkey =
"fragments.fragment";
172 std::vector<tools::Property*> fragments = seg->Select(fragkey);
176 std::vector<std::string> atomnames =
177 frag->get(
"mdatoms").as<std::vector<std::string>>();
179 for (
const std::string& atomname : atomnames) {
182 std::vector<std::string> entries = tok_atom_name.
ToVector();
183 if (entries.size() != 3) {
184 throw std::runtime_error(
"Atom entry " + atomname +
185 " is not well formatted");
191 atomid = std::stoi(entries[2]);
192 }
catch (std::invalid_argument&
e) {
193 throw std::runtime_error(
"Atom entry " + atomname +
194 " is not well formatted");
197 std::cout <<
"... ... processing mapping information for atom "
198 << atomname <<
" with ID " << atomid << std::endl;
200 atomids.push_back(atomid);
201 MolToSegMap[molname][atomid] = segname;
205 std::sort(atomids.begin(), atomids.end());
206 MolToAtomIds[molname] = atomids;
207 std::cout <<
"adding " << segnames[0] << std::endl;
208 SegsinMol[molname] = segnames;
221 std::map<Index, std::vector<Index>> bead_bonded_partners;
223 if (interaction->BeadCount() != 2) {
226 Index id1 = interaction->getBeadId(0);
227 Index id2 = interaction->getBeadId(1);
228 bead_bonded_partners[id1].push_back(id2);
229 bead_bonded_partners[id2].push_back(id1);
252 if (bead_bonded_partners.empty()) {
254 <<
"\nWARNING: the MD topology being mapped contains no real bond "
255 "connectivity at all (no bonded interactions were found within "
256 "it) -- this topology reader may only provide atom positions, "
257 "not real, actual bond data. Automatic H-saturation of cut "
258 "segment boundaries (used by e.g. the ipodcoupling calculator) "
259 "will not be able to detect any external bonds at all, and will "
260 "silently do nothing at all, rather than saturating anything -- "
261 "check that the real, actual topology file/reader used here "
262 "genuinely provides real bond data, not just atom positions."
270 const std::vector<std::string> segnames = SegsinMol[mol.getName()];
271 std::cout << segnames.size() << std::endl;
272 for (
auto segment : segnames) {
273 std::cout << segment << std::endl;
276 std::vector<Segment>& topology_segments = xtptop.
Segments();
282 std::cout <<
"... Mapping molecule " << mol.getId() <<
", name "
283 << mol.getName() <<
", # of segments " << segnames.size()
284 <<
", atomID offset " << IdOffset << std::endl;
287 for (
const std::string& segname : segnames) {
289 Index segid = topology_segments.size();
295 for (
const csg::Bead* bead : mol.Beads()) {
297 if (segname == MolToSegMap[mol.getName()][bead->getId() - IdOffset]) {
298 Atom atom(bead->getResnr(), bead->getName(), bead->getId(),
313 auto it = bead_bonded_partners.find(bead->getId());
314 if (it != bead_bonded_partners.end()) {
315 for (
Index partner_id : it->second) {
334 partner_mol = &candidate;
338 if (partner_mol ==
nullptr) {
342 partner_mol, MolToAtomIds[partner_mol->
getName()]);
343 std::string partner_segname =
344 MolToSegMap[partner_mol->
getName()]
345 [partner_bead->
getId() - partner_offset];
346 if (partner_segname != segname) {
347 Eigen::Vector3d direction =
348 (partner_bead->
getPos() - bead->getPos()) *
368 if (it != bead_bonded_partners.end()) {
369 for (
Index partner_id : it->second) {
378 topology_segments.push_back(this_segment);
402 std::map<Index, Index> md_atom_id_to_segment_id;
404 for (
const Atom& segatom : seg) {
405 md_atom_id_to_segment_id[segatom.getId()] = seg.getId();
409 for (
Atom& segatom : seg) {
410 if (!segatom.hasExternalBond()) {
414 md_atom_id_to_segment_id.find(segatom.getExternalBondPartnerAtomId());
415 if (it != md_atom_id_to_segment_id.end()) {
416 segatom.setExternalBondPartnerSegmentId(it->second);