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;
203 const std::vector<std::string> segnames = SegsinMol[mol.getName()];
204 std::vector<Segment>& topology_segments = xtptop.
Segments();
208 std::cout <<
"... Mapping molecule " << mol.getId() <<
", name "
209 << mol.getName() <<
", # of segments " << segnames.size()
210 <<
", atomID offset " << IdOffset << std::endl;
213 for (
const std::string& segname : segnames) {
215 Index segid = topology_segments.size();
221 for (
const csg::Bead* bead : mol.Beads()) {
223 if (segname == MolToSegMap[mol.getName()][bead->getId() - IdOffset]) {
224 Atom atom(bead->getResnr(), bead->getName(), bead->getId(),
230 topology_segments.push_back(this_segment);