Skip to content

Commit ef8d280

Browse files
committed
Added missing documentation
1 parent 356091e commit ef8d280

File tree

2 files changed

+81
-27
lines changed

2 files changed

+81
-27
lines changed

multibind/multibind.py

Lines changed: 74 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,35 @@
77

88
class MultibindDriver(object):
99

10+
"""Class to quickly run multibind over a range of pH values"""
11+
1012
def __init__(self, multibind):
13+
"""
14+
Parameters
15+
----------
16+
multibind : Multibind
17+
A multibind object with its states and graph attributed defined.
18+
19+
"""
1120
if not type(multibind.states) is None and not type(multibind.graph) is None:
1221
self.multibind = multibind
1322
else:
1423
raise ValueError(
1524
"Multibind driver must be passed a Multibind object that has states and a graph file loaded.")
1625

1726
def create_tensor(self, pH_array):
27+
"""Create a tensor containing state free energies across a pH range.
28+
29+
Parameters
30+
----------
31+
pH_array : iterable
32+
An iterable containing the pH values to calculate binding free energies for.
33+
34+
Returns
35+
-------
36+
None
37+
38+
"""
1839
num_states = self.multibind.states.name.shape[0]
1940
self.tensor = np.zeros((num_states, num_states, len(pH_array)))
2041

@@ -28,8 +49,14 @@ def create_tensor(self, pH_array):
2849
class Multibind(object):
2950

3051
def __init__(self, states_filename=None, graph_filename=None):
31-
# If states are specified in a CSV, may as well fill them in
32-
# here. The same goes for the graph information
52+
"""
53+
Parameters
54+
----------
55+
states_filename : str (optional)
56+
Path the CSV containing the states of the graph.
57+
graph_filename : str (optional)
58+
Path to the CSV containing the graph data for the network.
59+
"""
3360
if states_filename:
3461
self.read_states(states_filename)
3562
else:
@@ -44,10 +71,20 @@ def __init__(self, states_filename=None, graph_filename=None):
4471
self.concentrations = {}
4572

4673
def build_cycle(self, pH=5):
47-
"""Constructs the cycle used for calculation"""
74+
"""Constructs the cycle used for calculation
75+
76+
Parameters
77+
----------
78+
pH : float | int
79+
The pH to calculate binding free energies over.
80+
81+
Returns
82+
-------
83+
None
84+
"""
4885

4986
# Determine if we have enough information to continue,
50-
# ie states information and graph information
87+
# i.e. states information and graph information
5188
if type(self.states) is None or type(self.graph) is None:
5289
msg = "Need to specify both the state and graph \
5390
information. Try using `read_states` and `read_graph`."
@@ -169,6 +206,16 @@ def jacobian(g_t):
169206

170207
def MLE_dist(self, N_steps=int(1e6), nt=1):
171208
"""Run Monte-Carlo steps to assess quality of MLE results.
209+
210+
Parameters
211+
----------
212+
N_steps : int
213+
The number of Monte-Carlo steps to perform.
214+
215+
Returns
216+
-------
217+
ndarray with the distribution of free energy values for the states.
218+
172219
"""
173220

174221
def potential(g_t):
@@ -236,14 +283,17 @@ def effective_energy_difference(self, macrostate_class, state1, state2):
236283
"""Calculate the effective binding energy between two states.
237284
238285
Parameters
239-
==========
240-
macrostate_class : name of macrostate class (i.e. number of protons)
241-
state1 : first, 'starting' state
242-
state2 : second, 'destination' state
286+
----------
287+
macrostate_class : str
288+
Name of macrostate class (i.e. number of protons)
289+
state1 : str
290+
first, 'starting' state
291+
state2 : str
292+
second, 'destination' state
243293
244294
Returns
245-
=======
246-
float : binding free energy in kT
295+
-------
296+
float : macroscopic free energy difference in kT
247297
"""
248298

249299
macrostate_class = str(macrostate_class)
@@ -264,26 +314,31 @@ def _parse(self, filename, comment=None):
264314
raise e(f"Could not parse file {filename}")
265315

266316
def read_states(self, filename, comment=None):
267-
"""Read in state information from a state CSV file
317+
"""Read in state information from a state CSV file.
268318
269319
Parameters
270-
==========
271-
filename : string with the file path
320+
----------
321+
filename : str
322+
Path to the state CSV file.
323+
324+
Returns
325+
-------
326+
None
272327
"""
273328
self.states = self._parse(filename, comment=comment)
274329
self.states['name'] = self.states['name'].astype('str')
275330

276331
def read_graph(self, filename, comment=None):
277-
"""Read in the graph information from a graph CSV file
332+
"""Read in the graph information from a graph CSV file.
278333
279334
Parameters
280-
==========
281-
filename : string with the file path
335+
----------
336+
filename : str
337+
File path of the graph CSV
282338
283339
Returns
284-
=======
285-
DataFrame with graph information (accessible using `graph`
286-
attribute)
340+
-------
341+
None
287342
"""
288343
self.graph = self._parse(filename, comment=comment)
289344
self.graph['state1'] = self.graph['state1'].astype('str')

multibind/nonequilibrium.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66

77

88
def rate_matrix(filename: str):
9-
"""
9+
"""Build a rate matrix from a connectivity file with rates.
10+
11+
The rates are converted into free energy differences between states and
12+
then made thermodynamically consistent.
1013
1114
Parameters
1215
----------
@@ -42,8 +45,7 @@ def rate_matrix(filename: str):
4245

4346
# find all unique edges. Implicitly assumes that forward rates appear first...
4447
# todo add this to the docstring
45-
_edges.append((state1, state2)) if (
46-
(state1, state2) not in _edges and (state2, state1) not in _edges) else None
48+
_edges.append((state1, state2)) if ((state1, state2) not in _edges and (state2, state1) not in _edges) else None
4749

4850
states = pd.DataFrame({'name': _states}) # create dataframe for states, which only needs the names
4951

@@ -89,9 +91,6 @@ def rate_matrix(filename: str):
8991

9092
states, connections, g = c.states.name.values, c.graph[['state1', 'state2']].values, c.g_mle
9193

92-
forward = []
93-
reverse = []
94-
9594
n = states.shape[0]
9695
_rate_matrix = np.zeros((n, n))
9796

@@ -104,11 +103,11 @@ def rate_matrix(filename: str):
104103
b_weight = np.exp(-dg)
105104
try:
106105
s_ijji = var_ij / var_ji
107-
except ZeroDivisionError as e:
106+
except ZeroDivisionError:
108107
s_ijji = 1e12
109108
try:
110109
s_jiij = 1 / s_ijji
111-
except ZeroDivisionError as e:
110+
except ZeroDivisionError:
112111
s_jiij = 1e12
113112

114113
_k_ji = k_ij / (b_weight + s_ijji / b_weight ** 2) + k_ji / (b_weight ** 2 * s_jiij + 1)

0 commit comments

Comments
 (0)