Visualization Library 2.1.0

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
Molecule.hpp
Go to the documentation of this file.
1 /**************************************************************************************/
2 /* */
3 /* Visualization Library */
4 /* http://visualizationlibrary.org */
5 /* */
6 /* Copyright (c) 2005-2020, Michele Bosi */
7 /* All rights reserved. */
8 /* */
9 /* Redistribution and use in source and binary forms, with or without modification, */
10 /* are permitted provided that the following conditions are met: */
11 /* */
12 /* - Redistributions of source code must retain the above copyright notice, this */
13 /* list of conditions and the following disclaimer. */
14 /* */
15 /* - Redistributions in binary form must reproduce the above copyright notice, this */
16 /* list of conditions and the following disclaimer in the documentation and/or */
17 /* other materials provided with the distribution. */
18 /* */
19 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */
20 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */
21 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
22 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */
23 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
24 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
25 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
26 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
27 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
28 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
29 /* */
30 /**************************************************************************************/
31 
32 #ifndef Molecule_INCLUDE_ONCE
33 #define Molecule_INCLUDE_ONCE
34 
36 #include <vlMolecule/Atom.hpp>
37 #include <vlMolecule/Bond.hpp>
38 #include <vlGraphics/Geometry.hpp>
39 #include <vlGraphics/Actor.hpp>
40 #include <vlGraphics/ActorTree.hpp>
41 #include <vlGraphics/Text.hpp>
42 #include <vlCore/String.hpp>
43 #include <vlCore/KeyValues.hpp>
44 
45 namespace vl
46 {
48  typedef enum
49  {
55 
65  {
67 
68  public:
69  Molecule();
70  ~Molecule() { reset(); }
71  Molecule(const Molecule& other): Object(other) { operator=(other); }
72  Molecule& operator=(const Molecule& other);
73 
74  void reset();
75 
76  void setMoleculeName(const String& name) { mMoleculeName = name; }
77  const String moleculeName() const { return mMoleculeName; }
78 
79  unsigned int id() const { return mId; }
80  void setId(unsigned int id) { mId = id; }
81 
82  KeyValues* tags() { return mTags.get(); }
83  const KeyValues* tags() const { return mTags.get(); }
84 
85  const std::vector< ref<Atom> >& atoms() const { return mAtoms; }
86  std::vector< ref<Atom> >& atoms() { return mAtoms; }
87 
88  int atomCount() const { return (int)mAtoms.size(); }
89  const Atom* atom(int index) const;
90  Atom* atom(int index);
91  void addAtom(Atom* atom);
92  void eraseAtom(Atom*atom);
93  void eraseAtom(int index);
94  void eraseAllAtoms();
95 
96  const std::vector< ref<Bond> >& bonds() const { return mBonds; }
97  std::vector< ref<Bond> >& bonds() { return mBonds; }
98 
99  int bondCount() const { return (int)mBonds.size(); }
100  const Bond* bond(int index) const;
101  Bond* bond(int index);
102  const Bond* bond(Atom* a1, Atom* a2) const;
103  Bond* bond(Atom* a1, Atom* a2);
104  void addBond(Bond* bond);
105  Bond* addBond(Atom* a1, Atom* a2);
106  void eraseBond(Bond*bond);
107  void eraseBond(int bond);
108  void eraseBond(Atom* a1, Atom* a2);
109  void eraseBond(int a1, int a2);
110  void eraseAllBonds();
111 
112  void computeAtomAdjacency();
113  void incidentBonds(std::vector<Bond*>& inc_bonds, Atom* atom);
114 
116  const std::vector< ref<Atom> >& cycle(int i) const { return mCycles[i]; }
118  std::vector< ref<Atom> >& cycle(int i) { return mCycles[i]; }
119 
121  const std::vector< std::vector< ref<Atom> > >& cycles() const { return mCycles; }
123  std::vector< std::vector< ref<Atom> > >& cycles() { return mCycles; }
124 
128  void prepareForRendering();
129 
131  const ActorTree* actorTree() const { return mActorTree.get(); }
133  ActorTree* actorTree() { return mActorTree.get(); }
134 
136  void setCPKAtomColors();
138  void setAtomColors(const fvec4& color);
139 
141  void setCalculatedAtomRadii(float percentage=1.0f);
143  void setEmpiricalAtomRadii(float percentage=1.0f);
145  void setCovalentAtomRadii(float percentage=1.0f);
147  void setVanDerWaalsAtomRadii(float percentage=1.0f);
149  void setAtomRadii(float radius);
151  void setBondRadii(float radius);
152 
153  void setAtomTypeVisible(EAtomType type, bool visible);
154 
156  void setMoleculeStyle(EMoleculeStyle style) { mMoleculeStyle = style; }
158  EMoleculeStyle moleculeStyle() const { return mMoleculeStyle; }
159 
161  void setAtomDetail(int detail) { mAtomDetail = detail; }
163  int atomDetail() const { return mAtomDetail; }
164 
166  void setBondDetail(int detail) { mBondDetail = detail; }
168  int bondDetail() const { return mBondDetail; }
169 
170  float ringOffset() const { return mRingOffset; }
171  void setRingOffset(float offset) { mRingOffset = offset; }
172 
173  void setAromaticBondsColor(const fvec4& color);
174  void setAromaticRingColor(const fvec4& color) { mAromaticRingColor = color; }
175  const fvec4& aromaticRingColor() const { return mAromaticRingColor; }
176 
177  float lineWidth() const { return mLineWidth; }
178  bool smoothLines() const { return mSmoothLines; }
179 
180  void setLineWidth(float w) { mLineWidth = w; }
181  void setSmoothLines(bool smooth) { mSmoothLines = smooth; }
182 
184  Transform* transformTree() { return mTransformTree.get(); }
186  const Transform* transformTree() const { return mTransformTree.get(); }
187 
189  const Text* atomLabelTemplate() const { return mAtomLabelTemplate.get(); }
191  Text* atomLabelTemplate() { return mAtomLabelTemplate.get(); }
192 
194  void setShowAtomNames(bool show) { mShowAtomNames = show; }
196  bool showAtomNames() const{ return mShowAtomNames; }
197 
199  const Effect* atomLabelEffect() const { return mAtomLabelEffect.get(); }
201  Effect* atomLabelEffect() { return mAtomLabelEffect.get(); }
202 
204  void setMoleculeToActorMapEnabled(bool enabled) { mMoleculeToActorMapEnabled = enabled; }
206  bool isMoleculeToActorMapEnabled() const { return mMoleculeToActorMapEnabled; }
207 
209  void setActorToMoleculeMapEnabled(bool enabled) { mActorToMoleculeMapEnabled = enabled; }
211  bool isActorToMoleculeMapEnabled() const { return mActorToMoleculeMapEnabled; }
212 
214  const std::map< ref<Atom>, ref<Actor> >& atomToActorMap() const { return mAtomToActorMap; }
216  const std::map< ref<Actor>, ref<Atom> >& actorToAtomMap() const { return mActorToAtomMap; }
218  const std::map< ref<Bond>, ref<Actor> >& bondToActorMap() const { return mBondToActorMap; }
220  const std::map< ref<Actor>, ref<Bond> >& actorToBondMap() const { return mActorToBondMap; }
221 
223  std::map< ref<Atom>, ref<Actor> >& atomToActorMap() { return mAtomToActorMap; }
225  std::map< ref<Actor>, ref<Atom> >& actorToAtomMap() { return mActorToAtomMap; }
227  std::map< ref<Bond>, ref<Actor> >& bondToActorMap() { return mBondToActorMap; }
229  std::map< ref<Actor>, ref<Bond> >& actorToBondMap() { return mActorToBondMap; }
230 
231  protected:
232  void prepareAtomInsert(int bonus=100)
233  {
234  if (atoms().size() == atoms().capacity())
235  atoms().reserve(atoms().size() + bonus);
236  }
237  void prepareBondInsert(int bonus=100)
238  {
239  if (bonds().size() == bonds().capacity())
240  bonds().reserve(bonds().size() + bonus);
241  }
242  void wireframeStyle();
243  void atomsStyle();
244  void ballAndStickStyle();
245  void sticksStyle();
246  void generateRings();
247  void generateAtomLabels();
248  void generateAtomLabel(const Atom* atom, Transform* tr);
249 
250  protected:
254  std::vector< ref<Atom> > mAtoms;
255  std::vector< ref<Bond> > mBonds;
256  std::vector< std::vector< ref<Atom> > > mCycles;
257  std::map< ref<Atom>, ref<Actor> > mAtomToActorMap;
258  std::map< ref<Actor>, ref<Atom> > mActorToAtomMap;
259  std::map< ref<Bond>, ref<Actor> > mBondToActorMap;
260  std::map< ref<Actor>, ref<Bond> > mActorToBondMap;
265  unsigned int mId;
266  EMoleculeStyle mMoleculeStyle;
269  float mRingOffset;
270  float mLineWidth;
275  };
276 
281  VLMOLECULE_EXPORT bool loadMOL2(const String& path, std::vector< ref<Molecule> >& structures);
282 
287  VLMOLECULE_EXPORT bool loadMOL2(VirtualFile* vfile, std::vector< ref<Molecule> >& structures);
288 }
289 
290 #endif
The Molecule class is used to manage and render 3D molecular structures.
Definition: Molecule.hpp:64
bool mSmoothLines
Definition: Molecule.hpp:271
const Transform * transformTree() const
The transform tree used by the generated bonds, atoms and labels.
Definition: Molecule.hpp:186
std::vector< ref< Bond > > & bonds()
Definition: Molecule.hpp:97
std::map< ref< Bond >, ref< Actor > > mBondToActorMap
Definition: Molecule.hpp:259
Implements a 4x4 matrix transform used to define the position and orientation of an Actor...
Definition: Transform.hpp:72
An abstract class representing a file.
Definition: VirtualFile.hpp:60
Transform * transformTree()
The transform tree used by the generated bonds, atoms and labels.
Definition: Molecule.hpp:184
void setAtomDetail(int detail)
Geometrical detail used to render the atoms, usually between 0 and 3 (default is 2) ...
Definition: Molecule.hpp:161
unsigned int id() const
Definition: Molecule.hpp:79
EMoleculeStyle moleculeStyle() const
The rendering style of the molecule.
Definition: Molecule.hpp:158
float mLineWidth
Definition: Molecule.hpp:270
A Renderable that renders text with a given Font.
Definition: Text.hpp:50
The String class implements an advanced UTF16 (Unicode BMP) string manipulation engine.
Definition: String.hpp:62
const std::vector< ref< Atom > > & cycle(int i) const
Returns the i-th cycle.
Definition: Molecule.hpp:116
void setShowAtomNames(bool show)
Globally defines whether the atom names should be rendered or not. See also Atom::setShowAtomName().
Definition: Molecule.hpp:194
EMoleculeStyle mMoleculeStyle
Definition: Molecule.hpp:266
void setSmoothLines(bool smooth)
Definition: Molecule.hpp:181
KeyValues * tags()
Definition: Molecule.hpp:82
void setBondDetail(int detail)
Geometrical detail used to render the bonds, usually between 5 and 50 (default is 20) ...
Definition: Molecule.hpp:166
std::map< ref< Actor >, ref< Bond > > & actorToBondMap()
Maps an Actor to it&#39;s corresponding Bond.
Definition: Molecule.hpp:229
int atomDetail() const
Geometrical detail used to render the atoms, usually between 0 and 3 (default is 2) ...
Definition: Molecule.hpp:163
ref< Text > mAtomLabelTemplate
Definition: Molecule.hpp:263
const std::vector< ref< Bond > > & bonds() const
Definition: Molecule.hpp:96
bool mMoleculeToActorMapEnabled
Definition: Molecule.hpp:273
ref< ActorTree > mActorTree
Definition: Molecule.hpp:252
std::vector< ref< Atom > > & cycle(int i)
Returns the i-th cycle.
Definition: Molecule.hpp:118
const std::vector< std::vector< ref< Atom > > > & cycles() const
Returns the list of cycles.
Definition: Molecule.hpp:121
const std::map< ref< Bond >, ref< Actor > > & bondToActorMap() const
Maps a Bond to it&#39;s corresponding Actor.
Definition: Molecule.hpp:218
const std::vector< ref< Atom > > & atoms() const
Definition: Molecule.hpp:85
bool smoothLines() const
Definition: Molecule.hpp:178
void setMoleculeToActorMapEnabled(bool enabled)
If enabled the atomToActorMap() and bondToActorMap() maps will be compiled next time the molecule&#39;s g...
Definition: Molecule.hpp:204
std::vector< ref< Atom > > & atoms()
Definition: Molecule.hpp:86
#define VL_INSTRUMENT_CLASS(ClassName, BaseClass)
Definition: TypeInfo.hpp:122
const std::map< ref< Actor >, ref< Bond > > & actorToBondMap() const
Maps an Actor to it&#39;s corresponding Bond.
Definition: Molecule.hpp:220
int bondCount() const
Definition: Molecule.hpp:99
String mMoleculeName
Definition: Molecule.hpp:261
void setMoleculeName(const String &name)
Definition: Molecule.hpp:76
std::vector< ref< Bond > > mBonds
Definition: Molecule.hpp:255
Visualization Library main namespace.
void setRingOffset(float offset)
Definition: Molecule.hpp:171
std::map< ref< Atom >, ref< Actor > > & atomToActorMap()
Maps an Atom to it&#39;s corresponding Actor.
Definition: Molecule.hpp:223
EMoleculeStyle
Defines the main molecule styles.
Definition: Molecule.hpp:48
void setLineWidth(float w)
Definition: Molecule.hpp:180
ref< Transform > mTransformTree
Definition: Molecule.hpp:253
void prepareBondInsert(int bonus=100)
Definition: Molecule.hpp:237
void setActorToMoleculeMapEnabled(bool enabled)
If enabled the actorToAtomMap() and actorToBondMap() maps will be compiled next time the molecule&#39;s g...
Definition: Molecule.hpp:209
ActorTree * actorTree()
The ActorTree node containing the Actor[s] representing the molecule.
Definition: Molecule.hpp:133
std::map< ref< Actor >, ref< Atom > > mActorToAtomMap
Definition: Molecule.hpp:258
float mRingOffset
Definition: Molecule.hpp:269
The base class for all the reference counted objects.
Definition: Object.hpp:158
void setId(unsigned int id)
Definition: Molecule.hpp:80
const std::map< ref< Actor >, ref< Atom > > & actorToAtomMap() const
Maps an Actor to it&#39;s corresponding Atom.
Definition: Molecule.hpp:216
float ringOffset() const
Definition: Molecule.hpp:170
bool showAtomNames() const
Globally defines whether the atom names should be rendered or not. See also Atom::setShowAtomName().
Definition: Molecule.hpp:196
int atomCount() const
Definition: Molecule.hpp:88
const KeyValues * tags() const
Definition: Molecule.hpp:83
const ActorTree * actorTree() const
The ActorTree node containing the Actor[s] representing the molecule.
Definition: Molecule.hpp:131
std::vector< ref< Atom > > mAtoms
Definition: Molecule.hpp:254
float lineWidth() const
Definition: Molecule.hpp:177
Defines the sequence of Shader objects used to render an Actor.
Definition: Effect.hpp:91
Molecule(const Molecule &other)
Definition: Molecule.hpp:71
fvec4 mAromaticRingColor
Definition: Molecule.hpp:251
void setMoleculeStyle(EMoleculeStyle style)
The rendering style of the molecule.
Definition: Molecule.hpp:156
std::map< ref< Actor >, ref< Bond > > mActorToBondMap
Definition: Molecule.hpp:260
const Effect * atomLabelEffect() const
The Effect used to render the atom labels.
Definition: Molecule.hpp:199
void prepareAtomInsert(int bonus=100)
Definition: Molecule.hpp:232
const String moleculeName() const
Definition: Molecule.hpp:77
bool mShowAtomNames
Definition: Molecule.hpp:272
ref< Effect > mAtomLabelEffect
Definition: Molecule.hpp:264
const Text * atomLabelTemplate() const
The text settings to be used to render the atom labels.
Definition: Molecule.hpp:189
The Bond class represents a bond to be used with the Molecule class.
Definition: Bond.hpp:62
std::vector< std::vector< ref< Atom > > > & cycles()
Returns the list of cycles.
Definition: Molecule.hpp:123
std::map< ref< Atom >, ref< Actor > > mAtomToActorMap
Definition: Molecule.hpp:257
EAtomType
Element types.
Effect * atomLabelEffect()
The Effect used to render the atom labels.
Definition: Molecule.hpp:201
void setAromaticRingColor(const fvec4 &color)
Definition: Molecule.hpp:174
std::map< ref< Actor >, ref< Atom > > & actorToAtomMap()
Maps an Actor to it&#39;s corresponding Atom.
Definition: Molecule.hpp:225
The Atom class represents an atom to be used with the Molecule class.
Definition: Atom.hpp:51
Text * atomLabelTemplate()
The text settings to be used to render the atom labels.
Definition: Molecule.hpp:191
bool mActorToMoleculeMapEnabled
Definition: Molecule.hpp:274
VLMOLECULE_EXPORT bool loadMOL2(const String &path, std::vector< ref< Molecule > > &structures)
Loads a Tripos MOL2 file.
Definition: vlMOL2.cpp:168
The ActorTree class implements a generic tree whose nodes contain Actors.
Definition: ActorTree.hpp:62
const fvec4 & aromaticRingColor() const
Definition: Molecule.hpp:175
std::map< ref< Bond >, ref< Actor > > & bondToActorMap()
Maps a Bond to it&#39;s corresponding Actor.
Definition: Molecule.hpp:227
bool isActorToMoleculeMapEnabled() const
If enabled the actorToAtomMap() and actorToBondMap() maps will be compiled next time the molecule&#39;s g...
Definition: Molecule.hpp:211
bool isMoleculeToActorMapEnabled() const
If enabled the atomToActorMap() and bondToActorMap() maps will be compiled next time the molecule&#39;s g...
Definition: Molecule.hpp:206
const std::map< ref< Atom >, ref< Actor > > & atomToActorMap() const
Maps an Atom to it&#39;s corresponding Actor.
Definition: Molecule.hpp:214
ref< KeyValues > mTags
Definition: Molecule.hpp:262
A set of key/value pairs usually used to associate generic information, tags, attributes etc...
Definition: KeyValues.hpp:42
unsigned int mId
Definition: Molecule.hpp:265
std::vector< std::vector< ref< Atom > > > mCycles
Definition: Molecule.hpp:256
int bondDetail() const
Geometrical detail used to render the bonds, usually between 5 and 50 (default is 20) ...
Definition: Molecule.hpp:168