/* * Project: MoleCuilder * Description: creates and alters molecular systems * Copyright (C) 2010-2012 University of Bonn. All rights reserved. * * * This file is part of MoleCuilder. * * MoleCuilder is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * MoleCuilder is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with MoleCuilder. If not, see . */ /* * MoleculeOfAtomSelectionDescriptor.cpp * * Created on: Dec 11, 2010 * Author: heber */ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "CodePatterns/MemDebug.hpp" #include "Descriptors/MoleculeOfAtomSelectionDescriptor.hpp" #include "Descriptors/MoleculeOfAtomSelectionDescriptor_impl.hpp" #include "Helpers/helpers.hpp" #include "molecule.hpp" #include "World.hpp" MoleculeOfAtomSelectionDescriptor_impl::MoleculeOfAtomSelectionDescriptor_impl(){} MoleculeOfAtomSelectionDescriptor_impl::~MoleculeOfAtomSelectionDescriptor_impl(){} bool MoleculeOfAtomSelectionDescriptor_impl::predicate(std::pair molecule){ for (molecule::const_iterator iter = molecule.second->begin(); iter != molecule.second->end(); ++iter) { if (World::getInstance().isSelected(*iter)) return true; } return false; } molecule* MoleculeOfAtomSelectionDescriptor_impl::find(){ World::AtomSet &set = getSelectedAtoms(); for (World::AtomSet::internal_iterator iter = set.begin_internal(); iter != set.end_internal(); ++iter) { if (iter->second->getMolecule()) return iter->second->getMolecule(); } return 0; } std::vector MoleculeOfAtomSelectionDescriptor_impl::findAll(){ std::vector res; std::set temp; std::pair< std::set::iterator, bool> inserter; World::AtomSet &set = getSelectedAtoms(); for (World::AtomSet::internal_iterator iter = set.begin_internal(); iter != set.end_internal(); ++iter) { if (iter->second->getMolecule()) { inserter = temp.insert( iter->second->getMolecule() ); if (inserter.second) res.push_back(iter->second->getMolecule()); } } return res; } World::AtomSet& MoleculeOfAtomSelectionDescriptor_impl::getSelectedAtoms(){ return World::getInstance().selectedAtoms; } MoleculeDescriptor MoleculesByAtomSelection(){ return MoleculeDescriptor(MoleculeDescriptor::impl_ptr(new MoleculeOfAtomSelectionDescriptor_impl())); }