3939#include " MathUtils.hpp"
4040
4141Molecule::Molecule (int nat, const Eigen::VectorXd & chg, const Eigen::VectorXd & m,
42- const Eigen::MatrixX3d & geo, const std::vector<Atom> & at, const std::vector<Sphere> & sph)
42+ const Eigen::Matrix3Xd & geo, const std::vector<Atom> & at, const std::vector<Sphere> & sph)
4343 : nAtoms_(nat), charges_(chg), masses_(m), geometry_(geo), atoms_(at), spheres_(sph)
4444{
4545 rotor_ = findRotorType ();
4646}
4747
48+ Molecule::Molecule (int nat, const std::vector<Sphere> & sph)
49+ : nAtoms_(nat), spheres_(sph)
50+ {
51+ // This constructor is used when initializing the Molecule in EXPLICIT mode
52+ // charges are set to 1.0; masses are set based on the radii; geometry is set from the list of spheres
53+ charges_ = Eigen::VectorXd::Ones (nAtoms_);
54+ for (int i = 0 ; i < nAtoms_; ++i) {
55+ masses_ (i) = spheres_[i].radius ();
56+ geometry_.col (i) = spheres_[i].center ();
57+ double charge = charges_ (i);
58+ double mass = masses_ (i);
59+ // All the atoms are dummies
60+ atoms_[i] = Atom (" Dummy" , " Du" , charge, mass, mass, geometry_.col (i));
61+ }
62+ rotor_ = findRotorType ();
63+ }
64+
4865
4966Molecule::Molecule (const Molecule &other){
5067 *this = other;
@@ -65,14 +82,14 @@ Eigen::Matrix3d Molecule::inertiaTensor(){
6582
6683 for (int i = 0 ; i < nAtoms_; ++i){
6784 // Diagonal
68- inertia (0 ,0 ) += masses_ (i) * (geometry_ (i, 1 ) * geometry_ (i, 1 ) + geometry_ (i, 2 ) * geometry_ (i, 2 ));
69- inertia (1 ,1 ) += masses_ (i) * (geometry_ (i, 0 ) * geometry_ (i, 0 ) + geometry_ (i, 2 ) * geometry_ (i, 2 ));
70- inertia (2 ,2 ) += masses_ (i) * (geometry_ (i, 0 ) * geometry_ (i, 0 ) + geometry_ (i, 1 ) * geometry_ (i, 1 ));
85+ inertia (0 ,0 ) += masses_ (i) * (geometry_ (1 ,i ) * geometry_ (1 ,i ) + geometry_ (2 ,i ) * geometry_ (2 ,i ));
86+ inertia (1 ,1 ) += masses_ (i) * (geometry_ (0 ,i ) * geometry_ (0 ,i ) + geometry_ (2 ,i ) * geometry_ (2 ,i ));
87+ inertia (2 ,2 ) += masses_ (i) * (geometry_ (0 ,i ) * geometry_ (0 ,i ) + geometry_ (1 ,i ) * geometry_ (1 ,i ));
7188
7289 // Off-diagonal
73- inertia (0 ,1 ) -= masses_ (i) * (geometry_ (i, 0 ) * geometry_ (i, 1 ));
74- inertia (0 ,2 ) -= masses_ (i) * (geometry_ (i, 0 ) * geometry_ (i, 2 ));
75- inertia (1 ,2 ) -= masses_ (i) * (geometry_ (i, 1 ) * geometry_ (i, 2 ));
90+ inertia (0 ,1 ) -= masses_ (i) * (geometry_ (0 ,i ) * geometry_ (1 ,i ));
91+ inertia (0 ,2 ) -= masses_ (i) * (geometry_ (0 ,i ) * geometry_ (2 ,i ));
92+ inertia (1 ,2 ) -= masses_ (i) * (geometry_ (1 ,i ) * geometry_ (2 ,i ));
7693 }
7794 // Now symmetrize
7895 hermitivitize (inertia);
@@ -134,8 +151,8 @@ rotorType Molecule::findRotorType(){
134151void Molecule::translate (const Eigen::Vector3d &translationVector){
135152 // Translate the geometry_ matrix and update the geometric data in atoms_.
136153 for (int i = 0 ; i < nAtoms_; ++i){
137- geometry_.row (i) -= translationVector;
138- Eigen::Vector3d tmp = geometry_.row (i). transpose ( );
154+ geometry_.col (i) -= translationVector;
155+ Eigen::Vector3d tmp = geometry_.col (i );
139156 atoms_[i].atomCoord (tmp);
140157 }
141158}
@@ -149,7 +166,7 @@ void Molecule::rotate(const Eigen::Matrix3d &rotationMatrix){
149166 // Rotate the geometry_ matrix and update the geometric data in atoms_.
150167 geometry_ *= rotationMatrix; // The power of Eigen: geometry_ = geometry_ * rotationMatrix;
151168 for (int i = 0 ; i < nAtoms_; ++i){
152- Eigen::Vector3d tmp = geometry_.row (i). transpose ( );
169+ Eigen::Vector3d tmp = geometry_.col (i );
153170 atoms_[i].atomCoord (tmp);
154171 }
155172}
@@ -190,7 +207,7 @@ std::ostream & operator<<(std::ostream &os, const Molecule &m){
190207 os << " Center X Y Z " << std::endl;
191208 os << " ------------ ----------------- ----------------- -----------------" << std::endl;
192209 for (int i = 0 ; i < m.nAtoms_ ; ++i){
193- os << std::setw (10 ) << m.atoms_ [i].atomSymbol () << std::setw (15 ) <<m.geometry_ .row (i ).format (CleanFmt) << std::endl;
210+ os << std::setw (10 ) << m.atoms_ [i].atomSymbol () << std::setw (15 ) <<m.geometry_ .col (i). transpose ( ).format (CleanFmt) << std::endl;
194211 }
195212 } else {
196213 os << " No atoms in this molecule!" << std::endl;
0 commit comments