| [c42e60] | 1 | /*
 | 
|---|
 | 2 |  * Project: MoleCuilder
 | 
|---|
 | 3 |  * Description: creates and alters molecular systems
 | 
|---|
 | 4 |  * Copyright (C)  2010 University of Bonn. All rights reserved.
 | 
|---|
 | 5 |  * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
 | 
|---|
 | 6 |  */
 | 
|---|
 | 7 | 
 | 
|---|
 | 8 | /*
 | 
|---|
 | 9 |  * MoleculeOfAtomSelectionDescriptor.cpp
 | 
|---|
 | 10 |  *
 | 
|---|
 | 11 |  *  Created on: Dec 11, 2010
 | 
|---|
 | 12 |  *      Author: heber
 | 
|---|
 | 13 |  */
 | 
|---|
 | 14 | 
 | 
|---|
 | 15 | // include config.h
 | 
|---|
 | 16 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 17 | #include <config.h>
 | 
|---|
 | 18 | #endif
 | 
|---|
 | 19 | 
 | 
|---|
| [ad011c] | 20 | #include "CodePatterns/MemDebug.hpp"
 | 
|---|
| [c42e60] | 21 | 
 | 
|---|
 | 22 | #include "Descriptors/MoleculeOfAtomSelectionDescriptor.hpp"
 | 
|---|
 | 23 | #include "Descriptors/MoleculeOfAtomSelectionDescriptor_impl.hpp"
 | 
|---|
 | 24 | 
 | 
|---|
 | 25 | #include "Helpers/helpers.hpp"
 | 
|---|
 | 26 | 
 | 
|---|
 | 27 | #include "molecule.hpp"
 | 
|---|
 | 28 | #include "World.hpp"
 | 
|---|
 | 29 | 
 | 
|---|
 | 30 | MoleculeOfAtomSelectionDescriptor_impl::MoleculeOfAtomSelectionDescriptor_impl(){}
 | 
|---|
 | 31 | 
 | 
|---|
 | 32 | MoleculeOfAtomSelectionDescriptor_impl::~MoleculeOfAtomSelectionDescriptor_impl(){}
 | 
|---|
 | 33 | 
 | 
|---|
 | 34 | bool MoleculeOfAtomSelectionDescriptor_impl::predicate(std::pair<moleculeId_t,molecule*> molecule){
 | 
|---|
 | 35 |   for (molecule::const_iterator iter = molecule.second->begin();
 | 
|---|
 | 36 |       iter != molecule.second->end();
 | 
|---|
 | 37 |       ++iter) {
 | 
|---|
 | 38 |     if (World::getInstance().isSelected(*iter))
 | 
|---|
 | 39 |       return true;
 | 
|---|
 | 40 |   }
 | 
|---|
 | 41 |   return false;
 | 
|---|
 | 42 | }
 | 
|---|
 | 43 | 
 | 
|---|
 | 44 | molecule* MoleculeOfAtomSelectionDescriptor_impl::find(){
 | 
|---|
 | 45 |   World &instance = World::getInstance();
 | 
|---|
 | 46 |   for (World::AtomSelectionIterator iter = instance.beginAtomSelection();
 | 
|---|
 | 47 |       iter != instance.endAtomSelection();
 | 
|---|
 | 48 |       ++iter) {
 | 
|---|
 | 49 |     if (iter->second->getMolecule() != NULL)
 | 
|---|
 | 50 |       return iter->second->getMolecule();
 | 
|---|
 | 51 |   }
 | 
|---|
 | 52 |   return 0;
 | 
|---|
 | 53 | }
 | 
|---|
 | 54 | 
 | 
|---|
 | 55 | std::vector<molecule*> MoleculeOfAtomSelectionDescriptor_impl::findAll(){
 | 
|---|
 | 56 |   std::vector<molecule*> res;
 | 
|---|
 | 57 |   std::set<molecule*> temp;
 | 
|---|
 | 58 |   std::pair< std::set<molecule*>::iterator, bool> inserter;
 | 
|---|
 | 59 |   World &instance = World::getInstance();
 | 
|---|
 | 60 |   for (World::AtomSelectionIterator iter = instance.beginAtomSelection();
 | 
|---|
 | 61 |       iter != instance.endAtomSelection();
 | 
|---|
 | 62 |       ++iter) {
 | 
|---|
 | 63 |     if (iter->second->getMolecule() != NULL) {
 | 
|---|
 | 64 |       inserter = temp.insert( iter->second->getMolecule() );
 | 
|---|
 | 65 |       if (inserter.second)
 | 
|---|
 | 66 |         res.push_back(iter->second->getMolecule());
 | 
|---|
 | 67 |     }
 | 
|---|
 | 68 |   }
 | 
|---|
 | 69 |   return res;
 | 
|---|
 | 70 | }
 | 
|---|
 | 71 | 
 | 
|---|
 | 72 | MoleculeDescriptor MoleculesByAtomSelection(){
 | 
|---|
 | 73 |   return MoleculeDescriptor(MoleculeDescriptor::impl_ptr(new MoleculeOfAtomSelectionDescriptor_impl()));
 | 
|---|
 | 74 | }
 | 
|---|