44#include "hydrodynamics/ShapeBuilder.hpp"
46#include "hydrodynamics/CompositeShape.hpp"
47#include "hydrodynamics/Ellipsoid.hpp"
48#include "hydrodynamics/Sphere.hpp"
49#include "types/GayBerneAdapter.hpp"
50#include "types/LennardJonesAdapter.hpp"
54 Shape* ShapeBuilder::createShape(StuntDouble* sd) {
55 Shape* currShape = NULL;
56 if (sd->isDirectionalAtom()) {
57 currShape = internalCreateShape(
static_cast<DirectionalAtom*
>(sd));
58 }
else if (sd->isAtom()) {
59 currShape = internalCreateShape(
static_cast<Atom*
>(sd));
60 }
else if (sd->isRigidBody()) {
61 currShape = internalCreateShape(
static_cast<RigidBody*
>(sd));
66 Shape* ShapeBuilder::createShape(Molecule* mol) {
67 Molecule::IntegrableObjectIterator j;
70 if (mol->getNAtoms() == 1) {
71 Shape* molShape = createShape(mol->getAtomAt(0));
74 CompositeShape* molShape =
new CompositeShape();
75 for (sd = mol->beginIntegrableObject(j); sd != NULL;
76 sd = mol->nextIntegrableObject(j)) {
77 Shape* currShape = createShape(sd);
78 if (currShape != NULL) { molShape->addShape(currShape); }
80 molShape->setName(mol->getType());
86 Shape* ShapeBuilder::internalCreateShape(Atom* atom) {
87 AtomType* atomType = atom->getAtomType();
88 Shape* currShape = NULL;
89 LennardJonesAdapter lja = LennardJonesAdapter(atomType);
90 if (lja.isLennardJones()) {
91 currShape =
new Sphere(atom->getPos(), lja.getSigma() / 2.0);
92 currShape->setName(atom->getType());
95 std::vector<AtomType*> atChain = atomType->allYourBase();
96 std::vector<AtomType*>::iterator i;
97 for (i = atChain.begin(); i != atChain.end(); ++i) {
100 currShape =
new Sphere(atom->getPos(), etab.
GetVdwRad(obanum));
101 currShape->setName(atom->getType());
106 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
107 "Could not find atom type in default element.txt\n");
108 painCave.severity = OPENMD_ERROR;
109 painCave.isFatal = 1;
116 Shape* ShapeBuilder::internalCreateShape(DirectionalAtom* datom) {
117 AtomType* atomType = datom->getAtomType();
118 Shape* currShape = NULL;
119 LennardJonesAdapter lja = LennardJonesAdapter(atomType);
120 GayBerneAdapter gba = GayBerneAdapter(atomType);
121 if (gba.isGayBerne()) {
122 currShape =
new Ellipsoid(datom->getPos(), gba.getL() / 2.0,
123 gba.getD() / 2.0, datom->getA());
124 }
else if (lja.isLennardJones()) {
125 currShape =
new Sphere(datom->getPos(), lja.getSigma() / 2.0);
127 int obanum = etab.
GetAtomicNum((datom->getType()).c_str());
129 currShape =
new Sphere(datom->getPos(), etab.
GetVdwRad(obanum));
131 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
132 "Could not find atom type in default element.txt\n");
133 painCave.severity = OPENMD_ERROR;
134 painCave.isFatal = 1;
138 currShape->setName(datom->getType());
142 Shape* ShapeBuilder::internalCreateShape(RigidBody* rb) {
143 std::vector<Atom*>::iterator ai;
144 CompositeShape* compositeShape =
new CompositeShape;
146 for (atom = rb->beginAtom(ai); atom != NULL; atom = rb->nextAtom(ai)) {
147 Shape* currShape = NULL;
148 if (atom->isDirectionalAtom()) {
149 currShape = internalCreateShape(
static_cast<DirectionalAtom*
>(atom));
150 }
else if (atom->isAtom()) {
151 currShape = internalCreateShape(
static_cast<Atom*
>(atom));
153 if (currShape != NULL) {
154 compositeShape->addShape(currShape);
155 compositeShape->setName(rb->getType());
158 return compositeShape;
RealType GetVdwRad(int atomicnum)
int GetAtomicNum(const char *str)
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.