Molmodel
|
00001 #ifndef SimTK_MOLMODEL_COMPOUND_MODELER_H_ 00002 #define SimTK_MOLMODEL_COMPOUND_MODELER_H_ 00003 00004 /* -------------------------------------------------------------------------- * 00005 * SimTK Core: SimTK Molmodel * 00006 * -------------------------------------------------------------------------- * 00007 * This is part of the SimTK Core biosimulation toolkit originating from * 00008 * Simbios, the NIH National Center for Physics-Based Simulation of * 00009 * Biological Structures at Stanford, funded under the NIH Roadmap for * 00010 * Medical Research, grant U54 GM072970. See https://simtk.org. * 00011 * * 00012 * Portions copyright (c) 2009 Stanford University and the Authors. * 00013 * Authors: Christopher Bruns * 00014 * Contributors: * 00015 * * 00016 * Permission is hereby granted, free of charge, to any person obtaining a * 00017 * copy of this software and associated documentation files (the "Software"), * 00018 * to deal in the Software without restriction, including without limitation * 00019 * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 00020 * and/or sell copies of the Software, and to permit persons to whom the * 00021 * Software is furnished to do so, subject to the following conditions: * 00022 * * 00023 * The above copyright notice and this permission notice shall be included in * 00024 * all copies or substantial portions of the Software. * 00025 * * 00026 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 00027 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 00028 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * 00029 * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 00030 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 00031 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * 00032 * USE OR OTHER DEALINGS IN THE SOFTWARE. * 00033 * -------------------------------------------------------------------------- */ 00034 00035 00036 #include "molmodel/internal/common.h" 00037 #include "molmodel/internal/Compound.h" 00038 #include "molmodel/internal/AtomSubsystem.h" 00039 00040 namespace SimTK { 00041 00043 class SimTK_MOLMODEL_EXPORT CompoundModeler 00044 { 00045 public: 00046 00047 SimTK_DEFINE_UNIQUE_LOCAL_INDEX_TYPE(CompoundModeler, RigidUnitIndex); 00048 00049 // RigidUnit data structure is for use in modelCompounds() method 00050 class RigidUnit { 00051 public: 00052 RigidUnit(RigidUnitIndex ix, CompoundModeler& parent) 00053 : myIndex(ix), compoundModeler(&parent) 00054 {} 00055 00056 MassProperties calcMassProperties() const { 00057 Real mass = 0; 00058 Vec3 com(0); 00059 Inertia inertia(0); 00060 00061 std::set<AtomSubsystem::AtomIndex>::const_iterator a; 00062 for (a = clusterAtoms.begin(); a != clusterAtoms.end(); ++a) 00063 { 00064 const AtomSubsystem::Atom& ssAtom = 00065 compoundModeler->getAtomSubsystem().getAtom(*a); 00066 00067 Real ma = ssAtom.getMass(); 00068 mass += ma; 00069 com += ma * ssAtom.getStationInBodyFrame(); 00070 inertia += Inertia(ssAtom.getStationInBodyFrame(), ma); 00071 } 00072 if (mass > 0) com /= mass; 00073 00074 return MassProperties(mass, com, inertia); 00075 } 00076 00077 RigidUnit& setMobilizedBodyIndex(MobilizedBodyIndex ix) 00078 { 00079 assert(!bodyIx.isValid()); 00080 assert(ix.isValid()); 00081 bodyIx = ix; 00082 std::set<AtomSubsystem::AtomIndex>::iterator a; 00083 for (a = clusterAtoms.begin(); a != clusterAtoms.end(); ++a) 00084 compoundModeler->updAtomSubsystem().setAtomMobilizedBodyIndex(*a, ix); 00085 00086 return *this; 00087 } 00088 00089 void buildUp( 00090 AtomSubsystem::AtomIndex seedAtomIx, 00091 CompoundRep& compoundRep); 00092 00093 // TODO: these members should be private with accessors 00094 RigidUnitIndex parentId; // InvalidId implies parented to Ground 00095 Compound::BondCenterIndex inboardBondCenterIndex; 00096 Angle inboardBondDihedralAngle; 00097 Transform frameInTopCompoundFrame; // useful intermediate computation 00098 Transform frameInParentFrame; // what we ultimately want 00099 00100 CompoundModeler* compoundModeler; 00101 00102 MobilizedBodyIndex bodyIx; // populated toward the end 00103 RigidUnitIndex myIndex; 00104 00105 Compound::BondIndex inboardBondIndex; 00106 00107 std::set<AtomSubsystem::AtomIndex> clusterAtoms; 00108 }; 00109 00110 00111 // AtomBonding data structure represents one Atom in the modelCompounds() method 00112 class AtomBonding { 00113 public: 00114 AtomBonding() {} 00115 AtomBonding(Compound::AtomIndex compoundIx) 00116 : compoundAtomIndex(compoundIx) {} 00117 00118 AtomSubsystem::AtomIndex parentAtomIndex; // for finding rootiest atom in cluster 00119 RigidUnitIndex clusterIx; 00120 00121 // Store only those bonds that are part of the multibody tree structure 00122 std::set<AtomSubsystem::AtomIndex> treeBonds; 00123 std::set<AtomSubsystem::AtomIndex> freeTreeBonds; 00124 00125 Vec3 locationInBodyFrame; 00126 00127 Compound::AtomIndex getCompoundAtomIndex() const { 00128 return compoundAtomIndex; 00129 } 00130 00131 AtomBonding& setCompoundAtomIndex(Compound::AtomIndex ix) { 00132 compoundAtomIndex = ix; 00133 return (*this); 00134 } 00135 00136 private: 00137 Compound::AtomIndex compoundAtomIndex; 00138 }; 00139 00140 00141 00142 CompoundModeler(AtomSubsystem& atomSubsystem) 00143 : atomSubsystem(atomSubsystem) 00144 {} 00145 00146 const AtomSubsystem& getAtomSubsystem() const { 00147 return atomSubsystem; 00148 } 00149 AtomSubsystem& updAtomSubsystem() { 00150 return atomSubsystem; 00151 } 00152 const AtomBonding& getAtomBonding(AtomSubsystem::AtomIndex a) const { 00153 return atomBondings[a]; 00154 } 00155 AtomBonding& updAtomBonding(AtomSubsystem::AtomIndex a) { 00156 return atomBondings[a]; 00157 } 00158 const RigidUnit& getRigidUnit(RigidUnitIndex a) const { 00159 return rigidUnits[a]; 00160 } 00161 RigidUnit& updRigidUnit(RigidUnitIndex a) { 00162 return rigidUnits[a]; 00163 } 00164 00165 // This is intended to replace CompoundSystem.modelCompounds() 00166 void model(Compound& compound); 00167 00168 private: 00169 AtomSubsystem& atomSubsystem; 00170 std::vector<RigidUnit> rigidUnits; 00171 std::vector<AtomBonding> atomBondings; 00172 00173 }; 00174 00175 } // namespace SimTK 00176 00177 #endif // SimTK_MOLMODEL_COMPOUND_MODELER_H_