[c42e60] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
[0aa122] | 4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
---|
[94d5ac6] | 5 | *
|
---|
| 6 | *
|
---|
| 7 | * This file is part of MoleCuilder.
|
---|
| 8 | *
|
---|
| 9 | * MoleCuilder is free software: you can redistribute it and/or modify
|
---|
| 10 | * it under the terms of the GNU General Public License as published by
|
---|
| 11 | * the Free Software Foundation, either version 2 of the License, or
|
---|
| 12 | * (at your option) any later version.
|
---|
| 13 | *
|
---|
| 14 | * MoleCuilder is distributed in the hope that it will be useful,
|
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 17 | * GNU General Public License for more details.
|
---|
| 18 | *
|
---|
| 19 | * You should have received a copy of the GNU General Public License
|
---|
| 20 | * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
|
---|
[c42e60] | 21 | */
|
---|
| 22 |
|
---|
| 23 | /*
|
---|
| 24 | * MoleculeOfAtomSelectionDescriptor.cpp
|
---|
| 25 | *
|
---|
| 26 | * Created on: Dec 11, 2010
|
---|
| 27 | * Author: heber
|
---|
| 28 | */
|
---|
| 29 |
|
---|
| 30 | // include config.h
|
---|
| 31 | #ifdef HAVE_CONFIG_H
|
---|
| 32 | #include <config.h>
|
---|
| 33 | #endif
|
---|
| 34 |
|
---|
[ad011c] | 35 | #include "CodePatterns/MemDebug.hpp"
|
---|
[c42e60] | 36 |
|
---|
| 37 | #include "Descriptors/MoleculeOfAtomSelectionDescriptor.hpp"
|
---|
| 38 | #include "Descriptors/MoleculeOfAtomSelectionDescriptor_impl.hpp"
|
---|
| 39 |
|
---|
| 40 | #include "Helpers/helpers.hpp"
|
---|
| 41 |
|
---|
| 42 | #include "molecule.hpp"
|
---|
| 43 | #include "World.hpp"
|
---|
| 44 |
|
---|
| 45 | MoleculeOfAtomSelectionDescriptor_impl::MoleculeOfAtomSelectionDescriptor_impl(){}
|
---|
| 46 |
|
---|
| 47 | MoleculeOfAtomSelectionDescriptor_impl::~MoleculeOfAtomSelectionDescriptor_impl(){}
|
---|
| 48 |
|
---|
| 49 | bool MoleculeOfAtomSelectionDescriptor_impl::predicate(std::pair<moleculeId_t,molecule*> molecule){
|
---|
| 50 | for (molecule::const_iterator iter = molecule.second->begin();
|
---|
| 51 | iter != molecule.second->end();
|
---|
| 52 | ++iter) {
|
---|
| 53 | if (World::getInstance().isSelected(*iter))
|
---|
| 54 | return true;
|
---|
| 55 | }
|
---|
| 56 | return false;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | molecule* MoleculeOfAtomSelectionDescriptor_impl::find(){
|
---|
[ea7a50] | 60 | World::AtomSet &set = getSelectedAtoms();
|
---|
| 61 | for (World::AtomSet::internal_iterator iter = set.begin_internal();
|
---|
| 62 | iter != set.end_internal();
|
---|
[c42e60] | 63 | ++iter) {
|
---|
[ea7a50] | 64 | if (iter->second->getMolecule())
|
---|
[c42e60] | 65 | return iter->second->getMolecule();
|
---|
| 66 | }
|
---|
| 67 | return 0;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | std::vector<molecule*> MoleculeOfAtomSelectionDescriptor_impl::findAll(){
|
---|
| 71 | std::vector<molecule*> res;
|
---|
| 72 | std::set<molecule*> temp;
|
---|
| 73 | std::pair< std::set<molecule*>::iterator, bool> inserter;
|
---|
[ea7a50] | 74 | World::AtomSet &set = getSelectedAtoms();
|
---|
| 75 | for (World::AtomSet::internal_iterator iter = set.begin_internal();
|
---|
| 76 | iter != set.end_internal();
|
---|
[c42e60] | 77 | ++iter) {
|
---|
[ea7a50] | 78 | if (iter->second->getMolecule()) {
|
---|
[c42e60] | 79 | inserter = temp.insert( iter->second->getMolecule() );
|
---|
| 80 | if (inserter.second)
|
---|
| 81 | res.push_back(iter->second->getMolecule());
|
---|
| 82 | }
|
---|
| 83 | }
|
---|
| 84 | return res;
|
---|
| 85 | }
|
---|
| 86 |
|
---|
[ea7a50] | 87 | World::AtomSet& MoleculeOfAtomSelectionDescriptor_impl::getSelectedAtoms(){
|
---|
| 88 | return World::getInstance().selectedAtoms;
|
---|
| 89 | }
|
---|
| 90 |
|
---|
[c42e60] | 91 | MoleculeDescriptor MoleculesByAtomSelection(){
|
---|
| 92 | return MoleculeDescriptor(MoleculeDescriptor::impl_ptr(new MoleculeOfAtomSelectionDescriptor_impl()));
|
---|
| 93 | }
|
---|