Changeset d1c5e2 for src


Ignore:
Timestamp:
Feb 8, 2010, 4:23:03 PM (15 years ago)
Author:
Tillmann Crueger <crueger@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
7a1ce5
Parents:
fc1b24
Message:

Improved Descriptor mechanism to allow calculations using descriptors.

Location:
src/Descriptors
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/Descriptors/AtomDescriptor.cpp

    rfc1b24 rd1c5e2  
    1111
    1212#include <boost/bind.hpp>
     13#include <cassert>
    1314
    1415using namespace std;
     
    1920AtomDescriptor::AtomDescriptor()
    2021{
     22}
     23
     24AtomDescriptor::AtomDescriptor(const AtomDescriptor &desc) {
    2125}
    2226
     
    3034}
    3135
    32 AtomPredicateDescriptor::AtomPredicateDescriptor()
    33 {
    34 }
    35 
    36 AtomPredicateDescriptor::~AtomPredicateDescriptor()
    37 {
    38 }
    39 
    40 atom* AtomPredicateDescriptor::find() {
     36atom* AtomDescriptor::find() {
    4137  atoms_t atoms = getAtoms();
    42   atoms_iter_t res = find_if(atoms.begin(),atoms.end(),boost::bind(&AtomPredicateDescriptor::predicate,this,_1));
     38  atoms_iter_t res = find_if(atoms.begin(),atoms.end(),boost::bind(&AtomDescriptor::predicate,this,_1));
    4339  return (res!=atoms.end())?((*res).second):0;
    4440}
    4541
    46 vector<atom*> AtomPredicateDescriptor::findAll() {
     42vector<atom*> AtomDescriptor::findAll() {
    4743  vector<atom*> res;
    4844  atoms_t atoms = getAtoms();
     
    5349  }
    5450}
     51
     52// stuff for operators
     53
     54// AND
     55AtomAndDescriptor::AtomAndDescriptor(const AtomDescriptor &_lhs,const AtomDescriptor &_rhs){
     56  lhs=_lhs.clone();
     57  rhs=_rhs.clone();
     58}
     59
     60AtomAndDescriptor::AtomAndDescriptor(const AtomAndDescriptor &_desc)
     61{
     62  // the copy constructor needs it's parameter as const to work,
     63  // however we need to be able to transfer the ownership of the pointers
     64  // to the new method to avoid another cloning.
     65  //
     66  // the only place where the copy constructor is used for these classes,
     67  // is when returning a temporary.
     68  // this is one of the very rare cases when const_cast makes sense
     69  AtomAndDescriptor &desc = const_cast<AtomAndDescriptor&>(_desc);
     70  lhs = desc.lhs;
     71  rhs = desc.rhs;
     72}
     73
     74AtomAndDescriptor::~AtomAndDescriptor(){
     75}
     76
     77bool AtomAndDescriptor::predicate(std::pair<int,atom*> atom){
     78  return lhs->predicate(atom) && rhs->predicate(atom);
     79}
     80
     81AtomAndDescriptor::desc_ptr AtomAndDescriptor::clone() const{
     82  return desc_ptr(new AtomAndDescriptor(*lhs,*rhs));
     83}
     84
     85AtomAndDescriptor operator&&(const AtomDescriptor &lhs, const AtomDescriptor &rhs){
     86  return AtomAndDescriptor(lhs,rhs);
     87}
     88
     89// OR
     90
     91AtomOrDescriptor::AtomOrDescriptor(const AtomDescriptor &_lhs,const AtomDescriptor &_rhs){
     92  lhs=_lhs.clone();
     93  rhs=_rhs.clone();
     94}
     95
     96AtomOrDescriptor::AtomOrDescriptor(const AtomOrDescriptor &_desc)
     97{
     98  // the copy constructor needs it's parameter as const to work,
     99  // however we need to be able to transfer the ownership of the pointers
     100  // to the new method to avoid another cloning.
     101  //
     102  // the only place where the copy constructor is used for these classes,
     103  // is when returning a temporary.
     104  // this is one of the very rare cases when const_cast makes sense
     105  AtomOrDescriptor &desc = const_cast<AtomOrDescriptor&>(_desc);
     106  lhs = desc.lhs;
     107  rhs = desc.rhs;
     108}
     109
     110AtomOrDescriptor::~AtomOrDescriptor(){
     111}
     112
     113bool AtomOrDescriptor::predicate(std::pair<int,atom*> atom){
     114  return lhs->predicate(atom) || rhs->predicate(atom);
     115}
     116
     117AtomAndDescriptor::desc_ptr AtomOrDescriptor::clone() const{
     118  return desc_ptr(new AtomOrDescriptor(*lhs,*rhs));
     119}
     120
     121AtomOrDescriptor  operator||(const AtomDescriptor &lhs, const AtomDescriptor &rhs){
     122  return AtomOrDescriptor(lhs,rhs);
     123}
     124
     125// NOT
     126
     127AtomNotDescriptor::AtomNotDescriptor(const AtomDescriptor &_arg){
     128  arg = _arg.clone();
     129}
     130
     131AtomNotDescriptor::AtomNotDescriptor(const AtomNotDescriptor &_desc) {
     132  // the copy constructor needs it's parameter as const to work,
     133  // however we need to be able to transfer the ownership of the pointers
     134  // to the new method to avoid another cloning.
     135  //
     136  // the only place where the copy constructor is used for these classes,
     137  // is when returning a temporary.
     138  // this is one of the very rare cases when const_cast makes sense
     139  AtomNotDescriptor &desc = const_cast<AtomNotDescriptor&>(_desc);
     140  arg = desc.arg;
     141}
     142
     143AtomNotDescriptor::~AtomNotDescriptor()
     144{
     145}
     146
     147bool AtomNotDescriptor::predicate(std::pair<int,atom*> atom){
     148 return !(arg->predicate(atom));
     149}
     150
     151AtomAndDescriptor::desc_ptr AtomNotDescriptor::clone() const{
     152  return desc_ptr(new AtomNotDescriptor(*arg));
     153}
     154
     155AtomNotDescriptor operator!(const AtomDescriptor &arg){
     156  return AtomNotDescriptor(arg);
     157}
  • src/Descriptors/AtomDescriptor.hpp

    rfc1b24 rd1c5e2  
    99#define ATOMDESCRIPTOR_HPP_
    1010
    11 #include<vector>
    12 #include<map>
     11
     12#include <vector>
     13#include <map>
     14#include <boost/shared_ptr.hpp>
    1315#include "World.hpp"
    1416
     
    1820{
    1921public:
     22
     23  typedef boost::shared_ptr<AtomDescriptor> desc_ptr;
     24
    2025  friend atom* World::getAtom(AtomDescriptor& descriptor);
    2126  friend std::vector<atom*> World::getAllAtoms(AtomDescriptor& descriptor);
     
    2328  AtomDescriptor();
    2429  virtual ~AtomDescriptor();
     30  AtomDescriptor(const AtomDescriptor&);
     31
     32  virtual bool predicate(std::pair<int,atom*>)=0;
     33  // clone is only used internally to generate operators
     34  virtual desc_ptr clone() const=0;
    2535
    2636protected:
    27   virtual atom* find()=0;
    28   virtual std::vector<atom*> findAll()=0;
     37  virtual atom* find();
     38  virtual std::vector<atom*> findAll();
    2939  std::map<int,atom*>& getAtoms();
    3040};
    3141
    32 class AtomPredicateDescriptor : public AtomDescriptor{
     42class AtomAndDescriptor : public AtomDescriptor
     43{
     44  friend AtomAndDescriptor operator&&(const AtomDescriptor &lhs, const AtomDescriptor &rhs);
    3345public:
    34   AtomPredicateDescriptor();
    35   virtual ~AtomPredicateDescriptor();
     46  AtomAndDescriptor(const AtomAndDescriptor&);
     47  ~AtomAndDescriptor();
    3648
    37 protected:
    38   virtual atom *find();
    39   virtual std::vector<atom*> findAll();
    40   virtual bool predicate(std::pair<int,atom*>)=0;
     49  virtual desc_ptr clone() const;
     50  virtual bool predicate(std::pair<int,atom*>);
     51
     52private:
     53  desc_ptr lhs;
     54  desc_ptr rhs;
     55
     56  // private constructor to enforce construction through operators
     57  AtomAndDescriptor(const AtomDescriptor &_lhs, const AtomDescriptor &_rhs);
    4158};
    4259
     60class AtomOrDescriptor : public AtomDescriptor
     61{
     62  friend AtomOrDescriptor  operator||(const AtomDescriptor &lhs, const AtomDescriptor &rhs);
     63public:
     64  AtomOrDescriptor(const AtomOrDescriptor &);
     65  ~AtomOrDescriptor();
     66
     67  virtual desc_ptr clone() const;
     68  virtual bool predicate(std::pair<int,atom*>);
     69
     70private:
     71  desc_ptr lhs;
     72  desc_ptr rhs;
     73
     74  // private constructor to enforce construction through operators
     75  AtomOrDescriptor(const AtomDescriptor &_lhs, const AtomDescriptor &_rhs);
     76};
     77
     78class AtomNotDescriptor : public AtomDescriptor
     79{
     80  friend AtomNotDescriptor operator!(const AtomDescriptor &arg);
     81public:
     82  AtomNotDescriptor(const AtomNotDescriptor &);
     83  ~AtomNotDescriptor();
     84
     85  virtual desc_ptr clone() const;
     86  virtual bool predicate(std::pair<int,atom*>);
     87
     88private:
     89  desc_ptr arg;
     90
     91  // protected constructor to enforce construction through operators
     92  AtomNotDescriptor(const AtomDescriptor &_arg);
     93};
     94
     95// no true short circuit, but the test of the second descriptor wont be done
     96AtomAndDescriptor operator&&(const AtomDescriptor &lhs, const AtomDescriptor &rhs);
     97AtomOrDescriptor  operator||(const AtomDescriptor &lhs, const AtomDescriptor &rhs);
     98AtomNotDescriptor operator!(const AtomDescriptor &arg);
     99
    43100#endif /* ATOMDESCRIPTOR_HPP_ */
  • src/Descriptors/AtomIdDescriptor.cpp

    rfc1b24 rd1c5e2  
    1919{}
    2020
     21bool AtomIdDescriptor::predicate(std::pair<int,atom*> atom) {
     22  return atom.second->getId()==id;
     23}
     24
     25AtomDescriptor::desc_ptr AtomIdDescriptor::clone() const{
     26  return desc_ptr(new AtomIdDescriptor(id));
     27}
     28
     29#if 0
     30
     31// so far the lookuptable for Atoms-by-id does not work, since atoms don't get an ID upon creation.
     32// instead of this we rely on walking through all atoms.
    2133
    2234atom *AtomIdDescriptor::find(){
     
    3042  return (res)?(vector<atom*>(1,res)):(vector<atom*>());
    3143}
     44
     45#endif
  • src/Descriptors/AtomIdDescriptor.hpp

    rfc1b24 rd1c5e2  
    1717  virtual ~AtomIdDescriptor();
    1818
     19  bool predicate(std::pair<int,atom*> atom);
     20
     21  virtual desc_ptr clone() const;
     22
    1923protected:
     24#if 0
    2025  atom *find();
    2126  std::vector<atom*> findAll();
    22 
     27#endif
    2328private:
    2429  int id;
Note: See TracChangeset for help on using the changeset viewer.