Skip to content

Commit

Permalink
add gyration radius for post processing
Browse files Browse the repository at this point in the history
Signed-off-by: Conrad Huebler <[email protected]>
  • Loading branch information
conradhuebler committed Nov 9, 2023
1 parent 51487d3 commit 85fc5b3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/core/molecule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,35 @@ Position Molecule::Centroid(bool protons, int fragment) const
return GeometryTools::Centroid(getGeometryByFragment(fragment, protons));
}

Eigen::Vector3d Molecule::COM(bool protons, int fragment)
{
// todo implement heavy and fragements ...
if (m_mass < 1)
CalculateMass();
Eigen::Vector3d com = { 0, 0, 0 };
for (int i = 0; i < m_geometry.size(); ++i) {
double mass = Elements::AtomicMass[m_atoms[i]];
com(0) += mass * m_geometry[i][0];
com(1) += mass * m_geometry[i][1];
com(2) += mass * m_geometry[i][2];
}
com(0) /= m_mass;
com(1) /= m_mass;
com(2) /= m_mass;
return com;
}

double Molecule::GyrationRadius(bool protons, int fragment)
{
Eigen::Vector3d com = COM(protons, fragment);
double gyr = 0;
for (int i = 0; i < m_geometry.size(); ++i) {
gyr += ((com(0) - m_geometry[i][0]) * (com(0) - m_geometry[i][0]) + (com(0) - m_geometry[i][0]) * (com(0) - m_geometry[i][0]) + (com(0) - m_geometry[i][0]) * (com(0) - m_geometry[i][0]));
}
gyr /= double(m_geometry.size());
return gyr;
}

std::pair<int, Position> Molecule::Atom(int i) const
{
return std::pair<int, Position>(m_atoms[i], { m_geometry[i][0], m_geometry[i][1], m_geometry[i][2] });
Expand Down
3 changes: 3 additions & 0 deletions src/core/molecule.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ class Molecule
Molecule getFragmentMolecule(int fragment) const;

double CalculateDistance(int i, int j) const;
double GyrationRadius(bool hydrogen = true, int fragment = -1);

Geometry getGeometry(const IntPair& pair, bool protons = true) const;
Geometry getGeometry(std::vector<int> atoms, bool protons = true) const;
Geometry getGeometryByFragment(int fragment, bool protons = true) const;
Expand All @@ -109,6 +111,7 @@ class Molecule
bool setGeometryByFragment(const Geometry& geometry, int fragment, bool protons = true);

Position Centroid(bool hydrogen = true, int fragment = -1) const;
Eigen::Vector3d COM(bool hydrogen = true, int fragment = -1);
inline std::size_t AtomCount() const { return m_atoms.size(); }
std::vector<int> Atoms() const { return m_atoms; }
std::pair<int, Position> Atom(int i) const;
Expand Down
14 changes: 14 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,18 @@ int main(int argc, char **argv) {
Molecule mol = file.Next();
mol.writeXYZFile(outfile, Tools::RandomVector(0, mol.AtomCount()));
}
} else if (strcmp(argv[1], "-gyration") == 0) {
FileIterator file(argv[2]);
int count = 1;
double sum = 0;

while (!file.AtEnd()) {
Molecule mol = file.Next();
double gyr = mol.GyrationRadius();
sum += gyr;
std::cout << ":: " << gyr << " " << sum / double(count) << std::endl;
count++;
}
} else {
bool centered = false;
for (std::size_t i = 2; i < argc; ++i) {
Expand All @@ -838,6 +850,8 @@ int main(int argc, char **argv) {
mol.AnalyseIntermoleculeDistance();
std::cout << mol.Check() << std::endl
<< std::endl;
std::cout << mol.COM().transpose() << std::endl;
std::cout << mol.GyrationRadius() << std::endl;
/*
Hessian hess("gfn2", UFFParameterJson);
hess.setMolecule(mol);
Expand Down

0 comments on commit 85fc5b3

Please sign in to comment.