Molmodel

CompoundSystem.h

Go to the documentation of this file.
00001 #ifndef SimTK_MOLMODEL_COMPOUNDSYSTEM_H_
00002 #define SimTK_MOLMODEL_COMPOUNDSYSTEM_H_
00003 
00004 #include "SimTKsimbody.h"
00005 #include "molmodel/internal/common.h"
00006 #include "molmodel/internal/Compound.h"
00007 #include "molmodel/internal/MolecularMechanicsSystem.h"
00008 #include "molmodel/internal/DuMMForceFieldSubsystem.h"
00009 
00010 #include <map>
00011 
00012 namespace SimTK {
00013 
00019 class SimTK_MOLMODEL_EXPORT CompoundSystem : public MolecularMechanicsSystem {
00020 public:
00021 
00027     SimTK_DEFINE_UNIQUE_LOCAL_INDEX_TYPE(CompoundSystem,CompoundIndex);
00028 
00030     CompoundSystem() {}
00031 
00033     ~CompoundSystem() {
00034         for (int i=0; i < (int)compounds.size(); ++i)
00035             delete compounds[i];
00036     }
00037 
00038     // const SimbodyMatterSubsystem& getMatter() const {return matter;}
00039     // SimbodyMatterSubsystem& updMatter() {return matter;}
00040 
00041     // const DecorationSubsystem& getDecorations() const {return decorations;}
00042     // DecorationSubsystem& updDecorations() {return decorations;}
00043 
00050     void adoptCompound(
00051         Compound& child, 
00052         const Transform& compoundTransform = Transform() 
00053         ) 
00054     {
00055         // const Compound::Index id((int)compounds.size());
00056 
00057         compounds.push_back(new Compound((CompoundRep*)0)); // grow
00058         Compound& c = *compounds.back(); // refer to the empty handle we just created
00059 
00060         child.disown(c); // transfer ownership to c
00061 
00062         // Now tell the Compound object its owning CompoundSystem and id within
00063         // that System.
00064         // c.setCompoundSystem(*this, id);
00065         c.setMultibodySystem(*this);
00066 
00067         // Save transform
00068         // March 6, 2008 -- adjust internal Transform of Compound, rather than 
00069         // saving the Transform in CompoundSystem
00070         c.setTopLevelTransform(compoundTransform * c.getTopLevelTransform());
00071         // assert((int) compoundTransforms.size() == (int) id);
00072         // compoundTransforms.push_back(compoundTransform);
00073 
00074         // return id;
00075     }
00076 
00078     void modelCompounds();
00079 
00083     size_t             getNumCompounds() const {return compounds.size();}
00084 
00086     const Compound& getCompound(CompoundIndex i 
00087         ) const {return *compounds.at(i);}
00088 
00090     Compound&       updCompound(CompoundIndex i 
00091         )       {return *compounds.at(i);}
00092 
00093 private:
00094 
00095     void modelOneCompound(CompoundIndex compoundId);
00096 
00097     void setClusterCompound(DuMM::ClusterIndex clusterIx, const Compound& compound) 
00098     {
00099         assert(! clusterHasCompound(clusterIx));
00100         compoundPtrsByClusterIndex[clusterIx] = &compound;
00101         assert(clusterHasCompound(clusterIx));
00102     }
00103 
00104     bool clusterHasCompound(DuMM::ClusterIndex clusterIx) {
00105         return compoundPtrsByClusterIndex.find(clusterIx) != compoundPtrsByClusterIndex.end();
00106     }
00107 
00108     void generateTopologyFromCompounds();
00109 
00110     // suppress
00111     CompoundSystem(const CompoundSystem&);
00112     CompoundSystem& operator=(const CompoundSystem&);
00113 
00114     // std::vector<Transform> compoundTransforms;
00115 
00116     // retarded visual studio compiler complains about being unable to 
00117     // export private stl class members
00118 #if defined(_MSC_VER)
00119 #pragma warning(push)
00120 #pragma warning(disable:4251)
00121 #endif
00122 
00123     std::vector<Compound*> compounds;
00124     std::map<DuMM::ClusterIndex, const Compound*> compoundPtrsByClusterIndex;
00125     std::map<DuMM::ClusterIndex, int> clusterAtomCounts;
00126     std::map<DuMM::ClusterIndex, MobilizedBodyIndex> clusterBodies;
00127 
00128 #if defined(_MSC_VER)
00129 #pragma warning(pop)
00130 #endif
00131 
00132     // SimbodyMatterSubsystem matter;
00133     // DecorationSubsystem decorations;
00134 };
00135 
00136 } // namespace SimTK
00137 
00138 #endif // SimTK_MOLMODEL_COMPOUNDSYSTEM_H_
00139 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines