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");
146 std::map<std::string, std::map<Index, std::string>> MolToSegMap;
149 std::map<std::string, std::vector<Index>> MolToAtomIds;
152 std::map<std::string, std::vector<std::string>> SegsinMol;
154 std::string molkey =
"topology.molecules.molecule";
155 std::vector<tools::Property*> molecules = topology_map.
Select(molkey);
156 std::string segkey =
"segments.segment";
160 std::string molname = mol->get(
"mdname").as<std::string>();
162 std::vector<tools::Property*> segments = mol->Select(segkey);
163 std::vector<std::string> segnames;
164 std::vector<Index> atomids;
168 std::string segname = seg->get(
"name").as<std::string>();
169 segnames.push_back(segname);
171 std::cout <<
"... ... processing mapping information for segment "
172 << segname << std::endl;
174 std::string fragkey =
"fragments.fragment";
176 std::vector<tools::Property*> fragments = seg->Select(fragkey);
180 std::vector<std::string> atomnames =
181 frag->get(
"mdatoms").as<std::vector<std::string>>();
183 for (
const std::string& atomname : atomnames) {
186 std::vector<std::string> entries = tok_atom_name.
ToVector();
187 if (entries.size() != 3) {
188 throw std::runtime_error(
"Atom entry " + atomname +
189 " is not well formatted");
195 atomid = std::stoi(entries[2]);
196 }
catch (std::invalid_argument&
e) {
197 throw std::runtime_error(
"Atom entry " + atomname +
198 " is not well formatted");
201 std::cout <<
"... ... processing mapping information for atom "
202 << atomname <<
" with ID " << atomid << std::endl;
204 atomids.push_back(atomid);
205 MolToSegMap[molname][atomid] = segname;
209 std::sort(atomids.begin(), atomids.end());
210 MolToAtomIds[molname] = atomids;
212 std::cout <<
"... molecule " << molname <<
" has " << segnames.size()
213 <<
" segment(s)" << std::endl;
215 SegsinMol[molname] = segnames;
222 std::map<Index, std::vector<Index>> bead_bonded_partners;
224 if (interaction->BeadCount() != 2) {
227 Index id1 = interaction->getBeadId(0);
228 Index id2 = interaction->getBeadId(1);
229 bead_bonded_partners[id1].push_back(id2);
230 bead_bonded_partners[id2].push_back(id1);
238 if (bead_bonded_partners.empty()) {
240 <<
"\nWARNING: the MD topology contains no bonds (no 2-bead bonded "
241 "interactions found); the topology reader may only provide atom "
242 "positions. External bonds at cut segment boundaries cannot be "
243 "detected, so automatic H-saturation (e.g. in ipodcoupling) will "
244 "do nothing. Use a topology file/reader that provides bonds, or "
245 "xtp_map --guess-bonds."
249 std::vector<Index> atoms_with_several_external_bonds;
255 const std::vector<std::string> segnames = SegsinMol[mol.getName()];
257 std::vector<Segment>& topology_segments = xtptop.
Segments();
261 std::cout <<
"... Mapping molecule " << mol.getId() <<
", name "
262 << mol.getName() <<
", # of segments " << segnames.size()
263 <<
", atomID offset " << IdOffset << std::endl;
266 for (
const std::string& segname : segnames) {
268 Index segid = topology_segments.size();
274 for (
const csg::Bead* bead : mol.Beads()) {
276 if (segname == MolToSegMap[mol.getName()][bead->getId() - IdOffset]) {
277 Atom atom(bead->getResnr(), bead->getName(), bead->getId(),
286 auto it = bead_bonded_partners.find(bead->getId());
287 if (it != bead_bonded_partners.end()) {
288 Index n_external = 0;
289 for (
Index partner_id : it->second) {
297 partner_mol = &candidate;
301 if (partner_mol ==
nullptr) {
305 partner_mol, MolToAtomIds[partner_mol->
getName()]);
306 std::string partner_segname =
307 MolToSegMap[partner_mol->
getName()]
308 [partner_bead->
getId() - partner_offset];
309 if (partner_segname != segname) {
310 if (n_external == 0) {
312 Eigen::Vector3d direction =
317 partner_bead->
getId());
322 if (n_external > 1) {
323 atoms_with_several_external_bonds.push_back(bead->getId());
331 if (it != bead_bonded_partners.end()) {
332 for (
Index partner_id : it->second) {
341 topology_segments.push_back(this_segment);
345 if (!atoms_with_several_external_bonds.empty()) {
346 std::cout <<
"\nWARNING: " << atoms_with_several_external_bonds.size()
347 <<
" atom(s) have bonds into more than one other segment (first: "
349 << atoms_with_several_external_bonds.front()
350 <<
"). Only one external bond per atom is stored, so "
351 "H-saturation of cut segment boundaries (e.g. ipodcoupling) "
352 "and the search for linking segments use only that one. "
353 "Choose segment boundaries that cut at most one bond per "
364 std::map<Index, Index> md_atom_id_to_segment_id;
366 for (
const Atom& segatom : seg) {
367 md_atom_id_to_segment_id[segatom.getId()] = seg.getId();
371 for (
Atom& segatom : seg) {
372 if (!segatom.hasExternalBond()) {
376 md_atom_id_to_segment_id.find(segatom.getExternalBondPartnerAtomId());
377 if (it != md_atom_id_to_segment_id.end()) {
378 segatom.setExternalBondPartnerSegmentId(it->second);