Skip to content

Commit c140fea

Browse files
some work on API docs
1 parent 201c17c commit c140fea

File tree

5 files changed

+87
-29
lines changed

5 files changed

+87
-29
lines changed

cinnabar/arsenic.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
# this will combine a single command that will run all analysis and save everything
1+
"""
2+
cinnabar.arsenic
3+
================
4+
5+
Containing the command line interface usage of cinnabar.
6+
"""
27
import argparse
38

49
from . import FEMap, plotting

cinnabar/femap.py

+24-13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
"""
2+
FEMap
3+
=====
4+
5+
The workhorse of cinnabar, a :class:`FEMap` contains many measurements of free energy differences,
6+
both relative and absolute,
7+
which form an interconnected "network" of values.
8+
"""
19
import pathlib
210
from typing import Union
311
import copy
@@ -76,26 +84,28 @@ class FEMap:
7684
7785
Examples
7886
--------
79-
To read from a csv file specifically formatted for this, you can use:
80-
81-
>>> fe = FEMap.from_csv('../data/example.csv')
82-
83-
To construct manually:
87+
To construct a FEMap by hand:
8488
8589
>>> # Load/create experimental results
8690
>>> from openff.units import unit
8791
>>> kJpm = unit.kilojoule_per_mole
8892
>>> g = ReferenceState()
89-
>>> experimental_result1 = Measurement(labelA=g, labelB="CAT-13a", DG=-8.83 * kJpm, uncertainty=0.10 * kJpm)
90-
>>> experimental_result2 = Measurement(labelA=g, labelB="CAT-17g", DG=-9.73 * kJpm, uncertainty=0.10 * kJpm)
93+
>>> experimental_result1 = Measurement(labelA=g, labelB="CAT-13a", DG=-8.83 * kJpm, uncertainty=0.10 * kJpm,
94+
... computational=False)
95+
>>> experimental_result2 = Measurement(labelA=g, labelB="CAT-17g", DG=-9.73 * kJpm, uncertainty=0.10 * kJpm,
96+
... computational=False)
9197
>>> # Load/create calculated results
9298
>>> calculated_result = Measurement(labelA="CAT-13a", labelB="CAT-17g", DG=0.36 * kJpm,
93-
... uncertainty=0.11 * kJpm)
99+
... uncertainty=0.11 * kJpm, computational=True)
94100
>>> # Incrementally created FEMap
95101
>>> fe = FEMap()
96102
>>> fe.add_measurement(experimental_result1)
97103
>>> fe.add_measurement(experimental_result2)
98104
>>> fe.add_measurement(calculated_result)
105+
106+
To read from a legacy csv file specifically formatted for this, you can use:
107+
108+
>>> fe = FEMap.from_csv('../data/example.csv')
99109
"""
100110
# internal representation:
101111
# graph with measurements as edges
@@ -144,12 +154,13 @@ def to_networkx(self) -> nx.MultiDiGraph:
144154
The FEMap is represented as a multi-edged directional graph
145155
146156
Edges have the following attributes:
147-
- DG: the free energy difference of going from the first edge label to
157+
158+
* DG: the free energy difference of going from the first edge label to
148159
the second edge label
149-
- uncertainty: uncertainty of the DG value
150-
- temperature: the temperature at which DG was measured
151-
- computational: boolean label of the original source of the data
152-
- source: a string describing the source of data.
160+
* uncertainty: uncertainty of the DG value
161+
* temperature: the temperature at which DG was measured
162+
* computational: boolean label of the original source of the data
163+
* source: a string describing the source of data.
153164
154165
Note
155166
----

cinnabar/measurements.py

+51-12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
"""
2+
Measurements
3+
============
4+
5+
Contains the :class:`Measurement` class which is used to define a single free energy difference,
6+
as well as the :class:`ReferenceState` class which denotes the end point for absolute measurements.
7+
8+
"""
19
from openff.models.models import DefaultModel
210
from openff.models.types import FloatQuantity
311
from openff.units import unit
@@ -8,17 +16,10 @@
816
class ReferenceState:
917
"""A label indicating a reference point to which absolute measurements are relative
1018
11-
E.g. an absolute measurement for "LigandA" is defined as::
12-
13-
>>> m = Measurement(labelA=ReferenceState(), labelB='LigandA',
14-
... DG=2.4 * unit.kilocalorie_per_mol,
15-
... uncertainty=0.2 * unit.kilocalorie_per_mol,
16-
... source='gromacs')
17-
1819
A ``ReferenceState`` optionally has a label, which is used to differentiate
1920
it to other absolute measurements that might be relative to a different
20-
reference point. E.g. MLE measurements are against an arbitrary reference
21-
state that must be linked to the reference point of experiments.
21+
reference point. E.g. MLE estimations are against an arbitrary reference
22+
state that can be linked to the reference point of experiments.
2223
"""
2324
label: str
2425

@@ -33,6 +34,7 @@ def __init__(self, label: str = ""):
3334
self.label = label
3435

3536
def is_true_ground(self) -> bool:
37+
"""If this ReferenceState is the zero point of all other measurements"""
3638
return not self.label
3739

3840
def __repr__(self):
@@ -49,17 +51,52 @@ def __hash__(self):
4951

5052

5153
class Measurement(DefaultModel):
52-
"""The free energy difference of moving from A to B"""
54+
"""The free energy difference of moving from A to B
55+
56+
All quantities are accompanied by units, to prevent mix-ups associated with
57+
kcal and kJ. This is done via the `openff.units` package::
58+
59+
>>> m = Measurement(labelA='LigandA', labelB='LigandB',
60+
... DG=2.4 * unit.kilocalorie_per_mol,
61+
... uncertainty=0.2 * unit.kilocalorie_per_mol,
62+
... computational=True,
63+
... source='gromacs')
64+
65+
Alternatively strings are automatically coerced into quantities, making this
66+
equivalent to above::
67+
68+
>>> m = Measurement(labelA='LigandA', labelB='LigandB',
69+
... DG='2.4 kcal/mol',
70+
... uncertainty='0.2 kcal/mol',
71+
... computational=True,
72+
... source='gromacs')
73+
74+
Where a measurement is "absolute" then a `ReferenceState` can be used as the
75+
label at one end of the measurement. I.e. it is relative to a reference
76+
ground state. E.g. an absolute measurement for "LigandA" is defined as::
77+
78+
>>> m = Measurement(labelA=ReferenceState(), labelB='LigandA',
79+
... DG=-11.2 * unit.kilocalorie_per_mol,
80+
... uncertainty=0.3 * unit.kilocalorie_per_mol,
81+
... computational=False)
82+
"""
5383
class Config:
5484
frozen = True
5585

5686
labelA: Hashable
87+
"""Label of state A, e.g. a ligand name or any hashable Python object"""
5788
labelB: Hashable
89+
"""Label of state B"""
5890
DG: FloatQuantity['kilocalorie_per_mole']
91+
"""The free energy difference of moving from A to B"""
5992
uncertainty: FloatQuantity['kilocalorie_per_mole']
93+
"""The uncertainty of the DG measurement"""
6094
temperature: FloatQuantity['kelvin'] = 298.15 * unit.kelvin
95+
"""Temperature that the measurement was taken as"""
6196
computational: bool
97+
"""If this measurement is computationally based (or experimental)"""
6298
source: str = ""
99+
"""An arbitrary label to group measurements from a common source"""
63100

64101
@classmethod
65102
def from_experiment(cls,
@@ -70,7 +107,9 @@ def from_experiment(cls,
70107
source: str = '',
71108
temperature: unit.Quantity = 298.15 * unit.kelvin,
72109
):
73-
"""Create Measurement from experimental data
110+
"""Shortcut to create a Measurement from experimental data
111+
112+
Can perform conversion from Ki values to kcal/mol values.
74113
75114
Parameters
76115
----------
@@ -84,7 +123,7 @@ def from_experiment(cls,
84123
default is zero if no uncertainty is provided (0 * unit.nanomolar)
85124
source: str, optional
86125
source of experimental measurement
87-
temperature: unit.Quantity
126+
temperature: unit.Quantity, optional
88127
temperature in K at which the experimental measurement was carried out.
89128
By default: 298 K (298.15 * unit.kelvin)
90129
"""

docs/api.rst

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ API Documentation
22
=================
33

44
.. autosummary::
5-
:toctree: autosummary
5+
:toctree: generated
66

7-
cinnabar.plotting
7+
cinnabar.arsenic
8+
cinnabar.femap
9+
cinnabar.measurements
810
cinnabar.plotlying
11+
cinnabar.plotting
912
cinnabar.stats

docs/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@
167167
"cinnabar Documentation",
168168
author,
169169
"cinnabar",
170-
"Report results for free energy simualtions",
170+
"Report results for free energy simulations",
171171
"Miscellaneous",
172172
),
173173
]

0 commit comments

Comments
 (0)