/* * Project: MoleCuilder * Description: creates and alters molecular systems * Copyright (C) 2010 University of Bonn. All rights reserved. * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. */ /* * BuildInducedSubgraph.cpp * * Created on: Mar 3, 2011 * Author: heber */ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "CodePatterns/MemDebug.hpp" #include "BuildInducedSubgraph.hpp" #include "atom.hpp" #include "Bond/bond.hpp" #include "molecule.hpp" #include "CodePatterns/Assert.hpp" #include "CodePatterns/Log.hpp" #include "CodePatterns/Verbose.hpp" BuildInducedSubgraph::BuildInducedSubgraph(molecule * const _Son, const molecule * const _Father) : Son(_Son), Father(_Father) { // reset parent list ParentList.clear(); } BuildInducedSubgraph::~BuildInducedSubgraph() {} void BuildInducedSubgraph::FillParentList() { // fill parent list with sons LOG(3, "Filling Parent List."); for (molecule::const_iterator iter = Son->begin(); iter != Son->end(); ++iter) { ParentList[(*iter)->father] = (*iter); // Outputting List for debugging LOG(4, "INFO: ParentList[] of " << (*iter)->father << " is " << *ParentList[(*iter)->father] << "."); } } bool BuildInducedSubgraph::CreateBondsFromParent() { bool status = true; atom *OtherAtom = NULL; // check each entry of parent list and if ok (one-to-and-onto matching) create bonds LOG(2, "STATUS: Creating bonds."); for (molecule::const_iterator iter = Father->begin(); iter != Father->end(); ++iter) { if (ParentList.count(*iter)) { if (ParentList[(*iter)]->father != (*iter)) { status = false; } else { const BondList& ListOfBonds = (*iter)->getListOfBonds(); for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); ++Runner) { OtherAtom = (*Runner)->GetOtherAtom((*iter)); if (ParentList.count(OtherAtom)) { // if otheratom is also a father of an atom on this molecule, create the bond LOG(4, "INFO: Endpoints of Bond " << (*Runner) << " are both present: " << ParentList[(*iter)]->getName() << " and " << ParentList[OtherAtom]->getName() << "."); Son->AddBond(ParentList[(*iter)], ParentList[OtherAtom], (*Runner)->BondDegree); } } } } } return status; } bool BuildInducedSubgraph::operator()(){ bool status = true; FillParentList(); status = CreateBondsFromParent(); return status; }