| 1 | /*
 | 
|---|
| 2 |  * Project: MoleCuilder
 | 
|---|
| 3 |  * Description: creates and alters molecular systems
 | 
|---|
| 4 |  * Copyright (C)  2010-2012 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 | 
 | 
|---|
| 20 | #include "CodePatterns/MemDebug.hpp"
 | 
|---|
| 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::AtomSet &set = getSelectedAtoms();
 | 
|---|
| 46 |   for (World::AtomSet::internal_iterator iter = set.begin_internal();
 | 
|---|
| 47 |       iter != set.end_internal();
 | 
|---|
| 48 |       ++iter) {
 | 
|---|
| 49 |     if (iter->second->getMolecule())
 | 
|---|
| 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::AtomSet &set = getSelectedAtoms();
 | 
|---|
| 60 |   for (World::AtomSet::internal_iterator iter = set.begin_internal();
 | 
|---|
| 61 |       iter != set.end_internal();
 | 
|---|
| 62 |       ++iter) {
 | 
|---|
| 63 |     if (iter->second->getMolecule()) {
 | 
|---|
| 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 | World::AtomSet& MoleculeOfAtomSelectionDescriptor_impl::getSelectedAtoms(){
 | 
|---|
| 73 |   return World::getInstance().selectedAtoms;
 | 
|---|
| 74 | }
 | 
|---|
| 75 | 
 | 
|---|
| 76 | MoleculeDescriptor MoleculesByAtomSelection(){
 | 
|---|
| 77 |   return MoleculeDescriptor(MoleculeDescriptor::impl_ptr(new MoleculeOfAtomSelectionDescriptor_impl()));
 | 
|---|
| 78 | }
 | 
|---|