| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 2023766 commit 10840b3
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -624,6 +624,54 @@ void initAtoms(Eigen::VectorXd & charges_, Eigen::Matrix3Xd & sphereCenter_) | |||
| 624 | 624 | collect_atoms(chg, centers); | |
| 625 | 625 | } | |
| 626 | 626 | ||
| 627 | + void initMolecule(Molecule & molecule_) | ||
| 628 | + { | ||
| 629 | + // Gather information necessary to build molecule_ | ||
| 630 | + // 1. number of atomic centers | ||
| 631 | + int nuclei; | ||
| 632 | + collect_nctot(&nuclei); | ||
| 633 | + // 2. position and charges of atomic centers | ||
| 634 | + Eigen::Matrix3Xd centers = Eigen::Matrix3Xd::Zero(Eigen::NoChange, nuclei); | ||
| 635 | + Eigen::VectorXd charges = Eigen::VectorXd::Zero(nuclei); | ||
| 636 | + double * chg = charges.data(); | ||
| 637 | + double * pos = centers.data(); | ||
| 638 | + collect_atoms(chg, pos); | ||
| 639 | + // 3. list of atoms and list of spheres | ||
| 640 | + bool scaling = parsedInput->scaling(); | ||
| 641 | + std::string set = parsedInput->radiiSet(); | ||
| 642 | + double factor = angstromToBohr(parsedInput->CODATAyear()); | ||
| 643 | + std::vector<Atom> radiiSet, atoms; | ||
| 644 | + if ( set == "UFF" ) { | ||
| 645 | + radiiSet = Atom::initUFF(); | ||
| 646 | + } else { | ||
| 647 | + radiiSet = Atom::initBondi(); | ||
| 648 | + } | ||
| 649 | + std::vector<Sphere> spheres; | ||
| 650 | + for (int i = 0; i < charges.size(); ++i) { | ||
| 651 | + int index = int(charges(i)) - 1; | ||
| 652 | + atoms.push_back(radiiSet[index]); | ||
| 653 | + double radius = radiiSet[index].atomRadius() * factor; | ||
| 654 | + if (scaling) { | ||
| 655 | + radius *= radiiSet[index].atomRadiusScaling(); | ||
| 656 | + } | ||
| 657 | + spheres.push_back(Sphere(centers.col(i), radius)); | ||
| 658 | + } | ||
| 659 | + // 4. masses | ||
| 660 | + Eigen::VectorXd masses = Eigen::VectorXd::Zero(nuclei); | ||
| 661 | + for (int i = 0; i < masses.size(); ++i) { | ||
| 662 | + masses(i) = atoms[i].atomMass(); | ||
| 663 | + } | ||
| 664 | + // Based on the creation mode (Implicit or Atoms) | ||
| 665 | + // the spheres list might need postprocessing | ||
| 666 | + std::string _mode = parsedInput->mode(); | ||
| 667 | + if ( _mode == "ATOMS" ) { | ||
| 668 | + initSpheresAtoms(centers, spheres); | ||
| 669 | + } | ||
| 670 | + | ||
| 671 | + // OK, now get molecule_ | ||
| 672 | + molecule_ = Molecule(nuclei, charges, masses, centers, atoms, spheres); | ||
| 673 | + } | ||
| 674 | + | ||
| 627 | 675 | void initSpheresAtoms(const Eigen::Matrix3Xd & sphereCenter_, | |
| 628 | 676 | std::vector<Sphere> & spheres_) | |
| 629 | 677 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -40,6 +40,7 @@ | |||
| 40 | 40 | #include <Eigen/Dense> | |
| 41 | 41 | ||
| 42 | 42 | #include "InputManager.hpp" | |
| 43 | + #include "Molecule.hpp" | ||
| 43 | 44 | #include "Sphere.hpp" | |
| 44 | 45 | ||
| 45 | 46 | /* | |
@@ -311,6 +312,13 @@ void initWaveletCavity(); | |||
| 311 | 312 | */ | |
| 312 | 313 | void initAtoms(Eigen::VectorXd & charges_, Eigen::Matrix3Xd & sphereCenter_); | |
| 313 | 314 | ||
| 315 | + /*! \fn void initMolecule(Molecule & molecule_, Eigen::Matrix3Xd & sphereCenter_) | ||
| 316 | + * \param[out] molecule_ a Molecule object | ||
| 317 | + * | ||
| 318 | + * Initializes Molecule object with all the information on charges, masses and positions of atomic centers | ||
| 319 | + */ | ||
| 320 | + void initMolecule(Molecule & molecule_); | ||
| 321 | + | ||
| 314 | 322 | /*! \fn void initSpheresImplicit(const Eigen::VectorXd & charges_, const Eigen::Matrix3Xd & sphereCenter_, std::vector<Sphere> & spheres_) | |
| 315 | 323 | * \param[in] charges_ contains charges of atomic centers | |
| 316 | 324 | * \param[in] sphereCenter_ contains coordinates of atomic centers | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -142,14 +142,15 @@ void Input::reader(const char * pythonParsed) | |||
| 142 | 142 | if (mode_ == "EXPLICIT") { | |
| 143 | 143 | std::vector<double> spheresInput = cavity.getDblVec("SPHERES"); | |
| 144 | 144 | int j = 0; | |
| 145 | - int upperBound = int(spheresInput.size() / 4); | ||
| 146 | - for (int i = 0; i < upperBound; ++i) { | ||
| 145 | + int nAtoms = int(spheresInput.size() / 4); | ||
| 146 | + for (int i = 0; i < nAtoms; ++i) { | ||
| 147 | 147 | Eigen::Vector3d center; | |
| 148 | 148 | center << spheresInput[j], spheresInput[j+1], spheresInput[j+2]; | |
| 149 | 149 | Sphere sph(center, spheresInput[j+3]); | |
| 150 | 150 | spheres_.push_back(sph); | |
| 151 | 151 | j += 4; | |
| 152 | 152 | } | |
| 153 | + molecule_ = Molecule(nAtoms, spheres_); | ||
| 153 | 154 | } else if (mode_ == "ATOMS") { | |
| 154 | 155 | atoms_ = cavity.getIntVec("ATOMS"); | |
| 155 | 156 | radii_ = cavity.getDblVec("RADII"); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,6 +35,7 @@ | |||
| 35 | 35 | ||
| 36 | 36 | #include "Compression.hpp" | |
| 37 | 37 | #include "InputManager.hpp" | |
| 38 | + #include "Molecule.hpp" | ||
| 38 | 39 | #include "Solvent.hpp" | |
| 39 | 40 | #include "Sphere.hpp" | |
| 40 | 41 | ||
@@ -86,6 +87,8 @@ class Input | |||
| 86 | 87 | std::vector<Sphere> spheres() { return spheres_; } | |
| 87 | 88 | Sphere spheres(int i) { return spheres_[i]; } | |
| 88 | 89 | void spheres(const std::vector<Sphere> & sph) { spheres_ = sph; } | |
| 90 | + Molecule molecule() { return molecule_; } | ||
| 91 | + void molecule(const Molecule & m) { molecule_ = m; } | ||
| 89 | 92 | // Medium section input | |
| 90 | 93 | Solvent solvent() { return solvent_; } | |
| 91 | 94 | bool fromSolvent() { return hasSolvent_; } | |
@@ -168,6 +171,8 @@ class Input | |||
| 168 | 171 | std::vector<double> radii_; | |
| 169 | 172 | /// List of spheres for fully custom cavity generation | |
| 170 | 173 | std::vector<Sphere> spheres_; | |
| 174 | + /// Molecule or atomic aggregate | ||
| 175 | + Molecule molecule_; | ||
| 171 | 176 | /// The solvent for a vacuum/uniform dielectric run | |
| 172 | 177 | Solvent solvent_; | |
| 173 | 178 | /// Whether the medium was initialized from a solvent object | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -39,12 +39,29 @@ | |||
| 39 | 39 | #include "MathUtils.hpp" | |
| 40 | 40 | ||
| 41 | 41 | Molecule::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) | ||
| 43 | 43 | : nAtoms_(nat), charges_(chg), masses_(m), geometry_(geo), atoms_(at), spheres_(sph) | |
| 44 | 44 | { | |
| 45 | 45 | rotor_ = findRotorType(); | |
| 46 | 46 | } | |
| 47 | 47 | ||
| 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 | + | ||
| 48 | 65 | ||
| 49 | 66 | Molecule::Molecule(const Molecule &other){ | |
| 50 | 67 | *this = other; | |
@@ -65,14 +82,14 @@ Eigen::Matrix3d Molecule::inertiaTensor(){ | |||
| 65 | 82 | ||
| 66 | 83 | for (int i = 0; i < nAtoms_; ++i){ | |
| 67 | 84 | // 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)); | ||
| 71 | 88 | ||
| 72 | 89 | // 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)); | ||
| 76 | 93 | } | |
| 77 | 94 | // Now symmetrize | |
| 78 | 95 | hermitivitize(inertia); | |
@@ -134,8 +151,8 @@ rotorType Molecule::findRotorType(){ | |||
| 134 | 151 | void Molecule::translate(const Eigen::Vector3d &translationVector){ | |
| 135 | 152 | // Translate the geometry_ matrix and update the geometric data in atoms_. | |
| 136 | 153 | 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); | ||
| 139 | 156 | atoms_[i].atomCoord(tmp); | |
| 140 | 157 | } | |
| 141 | 158 | } | |
@@ -149,7 +166,7 @@ void Molecule::rotate(const Eigen::Matrix3d &rotationMatrix){ | |||
| 149 | 166 | // Rotate the geometry_ matrix and update the geometric data in atoms_. | |
| 150 | 167 | geometry_ *= rotationMatrix; // The power of Eigen: geometry_ = geometry_ * rotationMatrix; | |
| 151 | 168 | for (int i = 0; i < nAtoms_; ++i){ | |
| 152 | - Eigen::Vector3d tmp = geometry_.row(i).transpose(); | ||
| 169 | + Eigen::Vector3d tmp = geometry_.col(i); | ||
| 153 | 170 | atoms_[i].atomCoord(tmp); | |
| 154 | 171 | } | |
| 155 | 172 | } | |
@@ -190,7 +207,7 @@ std::ostream & operator<<(std::ostream &os, const Molecule &m){ | |||
| 190 | 207 | os << " Center X Y Z " << std::endl; | |
| 191 | 208 | os << " ------------ ----------------- ----------------- -----------------" << std::endl; | |
| 192 | 209 | 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; | ||
| 194 | 211 | } | |
| 195 | 212 | } else { | |
| 196 | 213 | os << " No atoms in this molecule!" << std::endl; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -60,7 +60,7 @@ class Molecule { | |||
| 60 | 60 | Eigen::VectorXd masses_; | |
| 61 | 61 | /// Molecular geometry, in cartesian coordinates. The dimensions are (# atoms * 3) | |
| 62 | 62 | /// Units are Bohr. | |
| 63 | - Eigen::MatrixX3d geometry_; | ||
| 63 | + Eigen::Matrix3Xd geometry_; | ||
| 64 | 64 | /// A container for all the atoms composing the molecule | |
| 65 | 65 | std::vector<Atom> atoms_; | |
| 66 | 66 | /// A container for the spheres composing the molecule | |
@@ -69,17 +69,17 @@ class Molecule { | |||
| 69 | 69 | rotorType rotor_; | |
| 70 | 70 | public: | |
| 71 | 71 | Molecule() {} | |
| 72 | - /// Constructor | ||
| 73 | 72 | Molecule(int nat, const Eigen::VectorXd & chg, const Eigen::VectorXd & masses, | |
| 74 | - const Eigen::MatrixX3d & geo, const std::vector<Atom> & at, const std::vector<Sphere> & sph); | ||
| 73 | + const Eigen::Matrix3Xd & geo, const std::vector<Atom> & at, const std::vector<Sphere> & sph); | ||
| 74 | + Molecule(int nat, const std::vector<Sphere> & sph); | ||
| 75 | 75 | /// Copy constructor. | |
| 76 | 76 | Molecule(const Molecule &other); | |
| 77 | 77 | ~Molecule(){} | |
| 78 | 78 | ||
| 79 | 79 | int nAtoms() { return nAtoms_; } | |
| 80 | 80 | Eigen::VectorXd charges() { return charges_; } | |
| 81 | 81 | Eigen::VectorXd masses() { return masses_; } | |
| 82 | - Eigen::MatrixX3d geometry() { return geometry_; } | ||
| 82 | + Eigen::Matrix3Xd geometry() { return geometry_; } | ||
| 83 | 83 | std::vector<Atom> atoms() { return atoms_; } | |
| 84 | 84 | std::vector<Sphere> spheres() { return spheres_; } | |
| 85 | 85 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments