-
Notifications
You must be signed in to change notification settings - Fork 1
Update doc strings #72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
b641826
552d6f8
d73ec02
6e08463
1e393d4
5ba4af2
a3f49f6
5b5b54a
b41bd7e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,22 +16,46 @@ | |
|
|
||
|
|
||
| def make_Universe(top: pathlib.Path, trj: nc.Dataset, state: int) -> mda.Universe: | ||
| """Makes a Universe and applies some transformations | ||
| """ | ||
| Construct an MDAnalysis Universe from a MultiState NetCDF trajectory | ||
| and apply standard analysis transformations. | ||
|
|
||
| The Universe is created using the custom ``FEReader`` to extract a | ||
| single state from a multistate simulation. | ||
|
|
||
| Identifies two AtomGroups: | ||
| - protein, defined as having standard amino acid names, then filtered | ||
| down to CA | ||
| - ligand, defined as resname UNK | ||
|
|
||
| Then applies some transformations. | ||
| Depending on whether a protein is present, a sequence of trajectory | ||
| transformations is applied: | ||
|
|
||
| If a protein is present: | ||
| - prevents the protein from jumping between periodic images | ||
| - moves the ligand to the image closest to the protein | ||
| - aligns the entire system to minimise the protein RMSD | ||
| (class:`NoJump`) | ||
| - moves the ligand to the image closest to the protein (:class:`Minimiser`) | ||
| - aligns the entire system to minimise the protein RMSD (:class:`Aligner`) | ||
|
|
||
| If only a ligand: | ||
| If only a ligand is present: | ||
| - prevents the ligand from jumping between periodic images | ||
| - Aligns the ligand to minimize its RMSD | ||
|
Comment on lines
26
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Details on the method should go under Notes I think. |
||
|
|
||
| Parameters | ||
| ---------- | ||
| top : pathlib.Path or Topology | ||
| Path to a topology file (e.g. PDB) or an already-loaded MDAnalysis | ||
| topology object. | ||
| trj : nc.Dataset | ||
| Open NetCDF dataset produced by | ||
| ``openmmtools.multistate.MultiStateReporter``. | ||
| state : int | ||
| Thermodynamic state index to extract from the multistate trajectory. | ||
|
|
||
| Returns | ||
| ------- | ||
| MDAnalysis.Universe | ||
| A Universe with trajectory transformations applied. | ||
| """ | ||
| u = mda.Universe( | ||
| top, | ||
|
|
@@ -76,23 +100,37 @@ def make_Universe(top: pathlib.Path, trj: nc.Dataset, state: int) -> mda.Univers | |
| def gather_rms_data( | ||
| pdb_topology: pathlib.Path, dataset: pathlib.Path, skip: Optional[int] = None | ||
| ) -> dict[str, list[float]]: | ||
| """Generate structural analysis of RBFE simulation | ||
| """ | ||
| Compute structural RMSD-based metrics for a multistate BFE simulation. | ||
|
|
||
| For each thermodynamic state (lambda), this function: | ||
| - Loads the trajectory using ``FEReader`` | ||
| - Applies standard PBC-handling and alignment transformations | ||
| - Computes protein and ligand structural metrics over time | ||
|
|
||
| The following analyses are produced per state: | ||
| - 1D protein CA RMSD time series | ||
| - 1D ligand RMSD time series | ||
| - Ligand center-of-mass displacement from its initial position | ||
| (``ligand_wander``) | ||
| - Flattened 2D protein RMSD matrix (pairwise RMSD between frames) | ||
|
Comment on lines
+106
to
+116
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think method details are best in a Notes section. |
||
|
|
||
| Parameters | ||
| ---------- | ||
| pdb_topology : pathlib.Path | ||
| path to pdb topology | ||
| Path to the PDB file defining system topology. | ||
| dataset : pathlib.Path | ||
| path to nc trajectory | ||
| Path to the NetCDF trajectory file produced by a multistate simulation. | ||
| skip : int, optional | ||
| step at which to progress through the trajectory. by default, selects a | ||
| step that produces roughly 500 frames of analysis per replicate | ||
|
|
||
| Produces, for each lambda state: | ||
| - 1D protein RMSD timeseries 'protein_RMSD' | ||
| - ligand RMSD timeseries | ||
| - ligand COM motion 'ligand_wander' | ||
| - 2D protein RMSD plot | ||
| Frame stride for analysis. If ``None``, a stride is chosen such that | ||
| approximately 500 frames are analyzed per state. | ||
|
|
||
| Returns | ||
| ------- | ||
| dict[str, list] | ||
| Dictionary containing per-state analysis results with keys: | ||
| ``protein_RMSD``, ``ligand_RMSD``, ``ligand_wander``, | ||
| ``protein_2D_RMSD``, and ``time(ps)``. | ||
| """ | ||
| output = { | ||
| "protein_RMSD": [], | ||
|
|
@@ -187,19 +225,25 @@ def gather_rms_data( | |
|
|
||
|
|
||
| def twoD_RMSD(positions, w: Optional[npt.NDArray]) -> list[float]: | ||
| """2 dimensions RMSD | ||
| """ | ||
| Compute a flattened 2D RMSD matrix from a trajectory. | ||
|
|
||
| For all unique frame pairs ``(i, j)`` with ``i < j``, this function | ||
| computes the RMSD between atomic coordinates after optimal alignment. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| positions : np.ndarray | ||
| the protein positions for the entire trajectory | ||
| Atomic coordinates for all frames in the trajectory. | ||
| w : np.ndarray, optional | ||
| weights array | ||
| Per-atom weights to use in the RMSD calculation. If ``None``, | ||
| all atoms are weighted equally. | ||
|
|
||
| Returns | ||
| ------- | ||
| rmsd_matrix : list | ||
| a flattened version of the 2d | ||
| list of float | ||
| Flattened list of RMSD values corresponding to all frame pairs | ||
| ``(i, j)`` with ``i < j``. | ||
| """ | ||
| nframes, _, _ = positions.shape | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,11 +14,32 @@ | |
|
|
||
|
|
||
| class NoJump(TransformationBase): | ||
| """Stops an AtomGroup from moving more than half a box length between frames | ||
|
|
||
| This transformation prevents an AtomGroup "teleporting" across the box | ||
| border between two subsequent frames. This then simplifies the calculation | ||
| of motion over time. | ||
| """ | ||
| Prevent an AtomGroup from jumping between periodic images. | ||
|
|
||
| This on-the-fly trajectory transformation removes large apparent | ||
| center-of-mass displacements caused by periodic boundary conditions. | ||
| If the AtomGroup moves by more than half a box length between | ||
| consecutive frames, it is translated by an integer number of box | ||
| vectors to keep its motion continuous. | ||
|
|
||
| The transformation operates in-place on the AtomGroup coordinates | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe this should be in the notes as well with the other caveats? |
||
| and is intended to be applied before analyses that rely on smooth | ||
| time evolution (e.g. RMSD, COM motion). | ||
|
|
||
| Parameters | ||
| ---------- | ||
| ag : MDAnalysis.AtomGroup | ||
| AtomGroup whose center-of-mass motion should be made continuous. | ||
|
|
||
| Notes | ||
| ----- | ||
| - This transformation assumes an orthorhombic unit cell. | ||
| - Only translations are applied; no rotations or scaling. | ||
| - The correction is based on center-of-mass motion and is therefore | ||
| most appropriate for compact groups (e.g. proteins, ligands). | ||
| - Must be applied before any alignment transformations to avoid | ||
| mixing reference frames. | ||
| """ | ||
|
|
||
| ag: mda.AtomGroup | ||
|
|
@@ -75,10 +96,13 @@ def _transform(self, ts): | |
|
|
||
|
|
||
| class Aligner(TransformationBase): | ||
| """On-the-fly transformation to align a trajectory to minimise RMSD | ||
| """ | ||
| Align a trajectory to a reference AtomGroup by minimizing RMSD. | ||
|
|
||
| centers all coordinates onto origin | ||
| rotates **entire universe** to minimise rmsd relative to **ref_ag** | ||
| This transformation performs an on-the-fly least-squares alignment | ||
| of the entire universe to a reference AtomGroup. | ||
| At each frame, the coordinates are translated and rotated to minimize the | ||
| RMSD of the atoms relative to their positions in the reference. | ||
|
Comment on lines
+102
to
+105
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets put all method details in notes sections. |
||
| """ | ||
|
|
||
| ref_pos: npt.NDArray | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably should be in the notes section?