Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef Molecule_INCLUDE_ONCE
00033 #define Molecule_INCLUDE_ONCE
00034
00035 #include <vlMolecule/link_config.hpp>
00036 #include <vlMolecule/Atom.hpp>
00037 #include <vlMolecule/Bond.hpp>
00038 #include <vlGraphics/Geometry.hpp>
00039 #include <vlGraphics/Actor.hpp>
00040 #include <vlGraphics/ActorTree.hpp>
00041 #include <vlGraphics/Text.hpp>
00042 #include <vlCore/String.hpp>
00043 #include <vlCore/KeyValues.hpp>
00044
00045 namespace vl
00046 {
00048 typedef enum
00049 {
00050 MS_AtomsOnly,
00051 MS_BallAndStick,
00052 MS_Sticks,
00053 MS_Wireframe,
00054 } EMoleculeStyle;
00055
00064 class VLMOLECULE_EXPORT Molecule: public Object
00065 {
00066 public:
00067 virtual const char* className() { return "vl::Molecule"; }
00068
00069 Molecule();
00070 ~Molecule() { reset(); }
00071 Molecule(const Molecule& other): Object(other) { operator=(other); }
00072 Molecule& operator=(const Molecule& other);
00073
00074 void reset();
00075
00076 void setMoleculeName(const String& name) { mMoleculeName = name; }
00077 const String moleculeName() const { return mMoleculeName; }
00078
00079 unsigned int id() const { return mId; }
00080 void setId(unsigned int id) { mId = id; }
00081
00082 KeyValues* tags() { return mTags.get(); }
00083 const KeyValues* tags() const { return mTags.get(); }
00084
00085 const std::vector< ref<Atom> >& atoms() const { return mAtoms; }
00086 std::vector< ref<Atom> >& atoms() { return mAtoms; }
00087
00088 int atomCount() const { return (int)mAtoms.size(); }
00089 Atom* atom(int index) const;
00090 void addAtom(Atom* atom);
00091 void eraseAtom(Atom*atom);
00092 void eraseAtom(int index);
00093 void eraseAllAtoms();
00094
00095 const std::vector< ref<Bond> >& bonds() const { return mBonds; }
00096 std::vector< ref<Bond> >& bonds() { return mBonds; }
00097
00098 int bondCount() const { return (int)mBonds.size(); }
00099 Bond* bond(int index) const;
00100 Bond* bond(Atom* a1, Atom* a2);
00101 void addBond(Bond* bond);
00102 Bond* addBond(Atom* a1, Atom* a2);
00103 void eraseBond(Bond*bond);
00104 void eraseBond(int bond);
00105 void eraseBond(Atom* a1, Atom* a2);
00106 void eraseBond(int a1, int a2);
00107 void eraseAllBonds();
00108
00109 void computeAtomAdjacency();
00110 void incidentBonds(std::vector<Bond*>& inc_bonds, Atom* atom);
00111
00113 const std::vector< ref<Atom> >& cycle(int i) const { return mCycles[i]; }
00115 std::vector< ref<Atom> >& cycle(int i) { return mCycles[i]; }
00116
00118 const std::vector< std::vector< ref<Atom> > >& cycles() const { return mCycles; }
00120 std::vector< std::vector< ref<Atom> > >& cycles() { return mCycles; }
00121
00125 void prepareForRendering();
00126
00128 const ActorTree* actorTree() const { return mActorTree.get(); }
00130 ActorTree* actorTree() { return mActorTree.get(); }
00131
00133 void setCPKAtomColors();
00135 void setAtomColors(const fvec4& color);
00136
00138 void setCalculatedAtomRadii(float percentage=1.0f);
00140 void setEmpiricalAtomRadii(float percentage=1.0f);
00142 void setCovalentAtomRadii(float percentage=1.0f);
00144 void setVanDerWaalsAtomRadii(float percentage=1.0f);
00146 void setAtomRadii(float radius);
00148 void setBondRadii(float radius);
00149
00150 void setAtomTypeVisible(EAtomType type, bool visible);
00151
00153 void setMoleculeStyle(EMoleculeStyle style) { mMoleculeStyle = style; }
00155 EMoleculeStyle moleculeStyle() const { return mMoleculeStyle; }
00156
00158 void setAtomDetail(int detail) { mAtomDetail = detail; }
00160 int atomDetail() const { return mAtomDetail; }
00161
00163 void setBondDetail(int detail) { mBondDetail = detail; }
00165 int bondDetail() const { return mBondDetail; }
00166
00167 float ringOffset() const { return mRingOffset; }
00168 void setRingOffset(float offset) { mRingOffset = offset; }
00169
00170 void setAromaticBondsColor(const fvec4& color);
00171 void setAromaticRingColor(const fvec4& color) { mAromaticRingColor = color; }
00172 const fvec4& aromaticRingColor() const { return mAromaticRingColor; }
00173
00174 float lineWidth() const { return mLineWidth; }
00175 bool smoothLines() const { return mSmoothLines; }
00176
00177 void setLineWidth(float w) { mLineWidth = w; }
00178 void setSmoothLines(bool smooth) { mSmoothLines = smooth; }
00179
00181 Transform* transformTree() { return mTransformTree.get(); }
00183 const Transform* transformTree() const { return mTransformTree.get(); }
00184
00186 Text* atomLabelTemplate() { return mAtomLabelTemplate.get(); }
00188 const Text* atomLabelTemplate() const { return mAtomLabelTemplate.get(); }
00189
00191 void setShowAtomNames(bool show) { mShowAtomNames = show; }
00193 bool showAtomNames() const{ return mShowAtomNames; }
00194
00196 const Effect* atomLabelEffect() const { return mAtomLabelEffect.get(); }
00198 Effect* atomLabelEffect() { return mAtomLabelEffect.get(); }
00199
00200 protected:
00201 void prepareAtomInsert(int bonus=100)
00202 {
00203 if (atoms().size() == atoms().capacity())
00204 atoms().reserve(atoms().size() + bonus);
00205 }
00206 void prepareBondInsert(int bonus=100)
00207 {
00208 if (bonds().size() == bonds().capacity())
00209 bonds().reserve(bonds().size() + bonus);
00210 }
00211 void wireframeStyle();
00212 void atomsStyle();
00213 void ballAndStickStyle();
00214 void sticksStyle();
00215 void generateRings();
00216 void generateAtomLabels();
00217 void generateAtomLabel(const Atom* atom, Transform* tr);
00218
00219 protected:
00220 fvec4 mAromaticRingColor;
00221 ref<ActorTree> mActorTree;
00222 ref<Transform> mTransformTree;
00223 std::vector< ref<Atom> > mAtoms;
00224 std::vector< ref<Bond> > mBonds;
00225 std::vector< std::vector< ref<Atom> > > mCycles;
00226 String mMoleculeName;
00227 ref<KeyValues> mTags;
00228 ref<Text> mAtomLabelTemplate;
00229 ref<Effect> mAtomLabelEffect;
00230 unsigned int mId;
00231 EMoleculeStyle mMoleculeStyle;
00232 int mAtomDetail;
00233 int mBondDetail;
00234 float mRingOffset;
00235 float mLineWidth;
00236 bool mSmoothLines;
00237 bool mShowAtomNames;
00238 };
00239
00244 VLMOLECULE_EXPORT bool loadMOL2(const String& path, std::vector< ref<Molecule> >& structures);
00245
00250 VLMOLECULE_EXPORT bool loadMOL2(VirtualFile* vfile, std::vector< ref<Molecule> >& structures);
00251 }
00252
00253 #endif