Changeset e60069
- Timestamp:
- Oct 18, 2009, 6:12:53 PM (16 years ago)
- Children:
- 99bed3
- Parents:
- 9897787
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
molecuilder/src/molecule_graph.cpp
r9897787 re60069 1154 1154 }; 1155 1155 1156 1157 /** Adds bond structure to this molecule from \a Father molecule. 1158 * This basically causes this molecule to become an induced subgraph of the \a Father, i.e. for every bond in Father 1159 * with end points present in this molecule, bond is created in this molecule. 1160 * Special care was taken to ensure that this is of complexity O(N), where N is the \a Father's molecule::AtomCount. 1161 * \param *out output stream for debugging 1162 * \param *Father father molecule 1163 * \return true - is induced subgraph, false - there are atoms with fathers not in \a Father 1164 * \todo not checked, not fully working probably 1165 */ 1166 bool molecule::BuildInducedSubgraph(ofstream *out, const molecule *Father) 1167 { 1168 atom *Walker = NULL, *OtherAtom = NULL; 1169 bool status = true; 1170 atom **ParentList = Malloc<atom*>(Father->AtomCount, "molecule::BuildInducedSubgraph: **ParentList"); 1171 1172 *out << Verbose(2) << "Begin of BuildInducedSubgraph." << endl; 1173 1156 void BuildInducedSubgraph_Init(ofstream *out, atom **&ParentList, int AtomCount) 1157 { 1174 1158 // reset parent list 1159 ParentList = Malloc<atom*>(AtomCount, "molecule::BuildInducedSubgraph_Init: **ParentList"); 1175 1160 *out << Verbose(3) << "Resetting ParentList." << endl; 1176 for (int i= Father->AtomCount;i--;)1161 for (int i=AtomCount;i--;) 1177 1162 ParentList[i] = NULL; 1178 1163 }; 1164 1165 void BuildInducedSubgraph_FillParentList(ofstream *out, const molecule *mol, const molecule *Father, atom **&ParentList) 1166 { 1179 1167 // fill parent list with sons 1180 1168 *out << Verbose(3) << "Filling Parent List." << endl; 1181 Walker =start;1182 while (Walker->next != end) {1169 atom *Walker = mol->start; 1170 while (Walker->next != mol->end) { 1183 1171 Walker = Walker->next; 1184 1172 ParentList[Walker->father->nr] = Walker; … … 1187 1175 } 1188 1176 1177 }; 1178 1179 void BuildInducedSubgraph_Finalize(ofstream *out, atom **&ParentList) 1180 { 1181 Free(&ParentList); 1182 }; 1183 1184 bool BuildInducedSubgraph_CreateBondsFromParent(ofstream *out, molecule *mol, const molecule *Father, atom **&ParentList) 1185 { 1186 bool status = true; 1187 atom *Walker = NULL; 1188 atom *OtherAtom = NULL; 1189 1189 // check each entry of parent list and if ok (one-to-and-onto matching) create bonds 1190 1190 *out << Verbose(3) << "Creating bonds." << endl; … … 1200 1200 if (ParentList[OtherAtom->nr] != NULL) { // if otheratom is also a father of an atom on this molecule, create the bond 1201 1201 *out << Verbose(4) << "Endpoints of Bond " << (*Runner) << " are both present: " << ParentList[Walker->nr]->Name << " and " << ParentList[OtherAtom->nr]->Name << "." << endl; 1202 AddBond(ParentList[Walker->nr], ParentList[OtherAtom->nr], (*Runner)->BondDegree);1202 mol->AddBond(ParentList[Walker->nr], ParentList[OtherAtom->nr], (*Runner)->BondDegree); 1203 1203 } 1204 1204 } … … 1206 1206 } 1207 1207 } 1208 1209 Free(&ParentList); 1208 return status; 1209 }; 1210 1211 /** Adds bond structure to this molecule from \a Father molecule. 1212 * This basically causes this molecule to become an induced subgraph of the \a Father, i.e. for every bond in Father 1213 * with end points present in this molecule, bond is created in this molecule. 1214 * Special care was taken to ensure that this is of complexity O(N), where N is the \a Father's molecule::AtomCount. 1215 * \param *out output stream for debugging 1216 * \param *Father father molecule 1217 * \return true - is induced subgraph, false - there are atoms with fathers not in \a Father 1218 * \todo not checked, not fully working probably 1219 */ 1220 bool molecule::BuildInducedSubgraph(ofstream *out, const molecule *Father) 1221 { 1222 bool status = true; 1223 atom **ParentList = NULL; 1224 1225 *out << Verbose(2) << "Begin of BuildInducedSubgraph." << endl; 1226 BuildInducedSubgraph_Init(out, ParentList, Father->AtomCount); 1227 BuildInducedSubgraph_FillParentList(out, this, Father, ParentList); 1228 status = BuildInducedSubgraph_CreateBondsFromParent(out, this, Father, ParentList); 1229 BuildInducedSubgraph_Finalize(out, ParentList); 1210 1230 *out << Verbose(2) << "End of BuildInducedSubgraph." << endl; 1211 1231 return status;
Note:
See TracChangeset
for help on using the changeset viewer.