Skip to content

Commit

Permalink
remove weight setting from rmsd calculation and corrected the documen…
Browse files Browse the repository at this point in the history
…tation.
  • Loading branch information
ChiCheng45 committed Apr 18, 2024
1 parent 7a3ea68 commit 63dc98c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 27 deletions.
23 changes: 9 additions & 14 deletions Doc/pages/structure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,10 @@ the difference between two structures. It can be defined as:
.. math::
:label: pfx131
{\mathit{RMSD}{(t) = \sqrt{\frac{\sum\limits_{\alpha = 1}^{N_{\alpha}}\left( {r_{\alpha}{(t) - r_{\alpha}}\left( t_{\mathit{ref}} \right)} \right)}{N_{\alpha}}}}}
{\mathit{RMSD}{(t) = \sqrt{\frac{\sum\limits_{\alpha}^{N_{\alpha}}\vert {r_{\alpha}{(t) - r_{\alpha}}\left( t_{\mathrm{ref}} \right)} \vert^{2}}{N_{\alpha}}}}}
where N\_ is the number of atoms of the system, and r_(t) and r_(tref )
are respectively the position of atom :math:`\alpha` at time t and tref where tref is
where :math:`N_{\alpha}` is the number of selected atoms of the system and :math:`r_{\alpha}(t)` and :math:`r_{\alpha}(t_{\mathrm{ref}})`
are respectively the position of atom :math:`\alpha` at time :math:`t` and :math:`t_{\mathrm{ref}}` where :math:`t_{\mathrm{ref}}` is
a reference time usually chosen as the first step of the simulation.
Typically, *RMSD* is used to quantify the structural evolution of the
system during the simulation. It can provide precious information about
Expand All @@ -268,23 +268,18 @@ structural changes occurred during the simulation.

In Molecular Dynamics Analysis for Neutron Scattering Experiments
(*MDANSE*), *RMSD* is computed using the discretized version of equation
:math:numref:`pfx130`:
:math:numref:`pfx131`:

.. math::
:label: pfx132
{\mathit{RMSD}{\left( {n\cdot\Delta t} \right) = \sqrt{\frac{\sum\limits_{\alpha = 1}^{N_{\alpha}}\left( {r_{\alpha}{(t) - r_{\mathit{ref}}}(t)} \right)}{N_{\alpha}}}},{n = 0}\ldots{N_{t} - 1}.}
{\mathit{RMSD}{\left( {n\Delta t} \right) = \sqrt{\frac{\sum\limits_{\alpha}^{N_{\alpha}}\vert {r_{\alpha}{(t) - r_{\alpha}}(t_{\mathrm{ref}})} \vert^{2}}{N_{\alpha}}}} \qquad {n = 0}\ldots{N_{t} - 1}.}
where Nt is the number of frames and
where :math:`N_{t}` is the number of frames and :math:`\mathrm{\Delta}t` is the time step.
Additionally MDANSE will also calculate the RMSD of individual atoms types,
for example, the RMSD of the oxygen atoms in addition to the RMSD of all
atoms of the system.

.. math::
:label: pfx133
{\mathrm{\Delta}t}
\ is the time step.

.

Root Mean Square Fluctuation
''''''''''''''''''''''''''''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ def configure(self, value):
self.error_status = "OK"

def get_natoms(self):
"""
Returns
-------
dict
A dictionary with the atom name for the key and
number of atoms selected for its value.
"""
nAtomsPerElement = {}
for v in self["names"]:
if v in nAtomsPerElement:
Expand All @@ -102,6 +109,15 @@ def get_natoms(self):

return nAtomsPerElement

def get_total_natoms(self):
"""
Returns
-------
int
The total number of atoms selected.
"""
return len(self["names"])

def get_indexes(self):
indexesPerElement = {}
for i, v in enumerate(self["names"]):
Expand Down
25 changes: 12 additions & 13 deletions MDANSE/Src/MDANSE/Framework/Jobs/RootMeanSquareDeviation.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ class RootMeanSquareDeviation(IJob):
}
},
)
settings["weights"] = (
"WeightsConfigurator",
{"dependencies": {"atom_selection": "atom_selection"}},
)
settings["output_files"] = (
"OutputFilesConfigurator",
{"formats": ["MDAFormat", "TextFormat"]},
Expand All @@ -94,7 +90,7 @@ def initialize(self):
units="ps",
)

# Will store the mean square deviation
# Will initially store the mean square deviation before appling the root
for element in self.configuration["atom_selection"]["unique_names"]:
self._outputData.add(
"rmsd_{}".format(element),
Expand All @@ -103,6 +99,13 @@ def initialize(self):
axis="time",
units="nm",
)
self._outputData.add(
"rmsd_all",
"LineOutputVariable",
(self.configuration["frames"]["number"],),
axis="time",
units="nm",
)

self._atoms = sorted_atoms(
self.configuration["trajectory"]["instance"].chemical_system.atom_list
Expand Down Expand Up @@ -142,29 +145,25 @@ def combine(self, index, x):
element = self.configuration["atom_selection"]["names"][index]

self._outputData["rmsd_%s" % element] += x
self._outputData["rmsd_all"] += x

def finalize(self):
"""
Finalize the job.
"""

# The RMSDs per element are averaged.
nAtomsPerElement = self.configuration["atom_selection"].get_natoms()
for element, number in nAtomsPerElement.items():
self._outputData["rmsd_{}".format(element)] /= number

weights = self.configuration["weights"].get_weights()
rmsdTotal = weight(weights, self._outputData, nAtomsPerElement, 1, "rmsd_%s")
rmsdTotal = np.sqrt(rmsdTotal)
self._outputData.add(
"rmsd_total", "LineOutputVariable", rmsdTotal, axis="time", units="nm"
)

for element, number in nAtomsPerElement.items():
self._outputData["rmsd_{}".format(element)] = np.sqrt(
self._outputData["rmsd_{}".format(element)]
)

self._outputData["rmsd_all"] /= self.configuration["atom_selection"].get_total_natoms()
self._outputData["rmsd_all"] = np.sqrt(self._outputData["rmsd_total"])

self._outputData.write(
self.configuration["output_files"]["root"],
self.configuration["output_files"]["formats"],
Expand Down

0 comments on commit 63dc98c

Please sign in to comment.