7
7
8
8
:mod:`~mdpow.workflows.dihedrals` module provides functions for automated
9
9
workflows that encompass :class:`~mdpow.analysis.dihedral.DihedralAnalysis`.
10
- See each function for requirements and examples.
10
+ See each function for requirements and examples.
11
11
12
12
Most functions can be used as standalone, individually, or in combination
13
13
depending on the desired results. Details of the completely automated workflow
42
42
import seaborn as sns
43
43
import matplotlib .pyplot as plt
44
44
45
- import mdpow
46
- from mdpow .analysis .dihedral import DihedralAnalysis
47
-
48
45
import MDAnalysis as mda
49
46
from MDAnalysis .topology .guessers import guess_atom_element
50
47
48
+ from ..analysis import ensemble , dihedral
49
+
51
50
import logging
52
51
53
52
logger = logging .getLogger ('mdpow.workflows.dihedrals' )
92
91
def build_universe (dirname ):
93
92
"""Builds :class:`~MDAnalysis.core.universe.Universe` from
94
93
``water/Coulomb/0000`` topology and trajectory for the specified project.
95
-
94
+
96
95
Used by :func:`~mdpow.workflows.dihedrals.rdkit_conversion`
97
96
and :func:`~mdpow.workflows.dihedrals.dihedral_indices` to obtain atom indices
98
97
for each dihedral atom group.
99
-
98
+
100
99
:keywords:
101
100
102
101
*dirname*
@@ -108,12 +107,12 @@ def build_universe(dirname):
108
107
searches for .gro, .gro.bz2, .gro.gz, and .tpr files for topology,
109
108
and .xtc files for trajectory. It will default to using the tpr file
110
109
available.
111
-
110
+
112
111
:returns:
113
112
114
113
*u*
115
114
:class:`~MDAnalysis.core.universe.Universe` object
116
-
115
+
117
116
"""
118
117
119
118
path = pathlib .Path (dirname )
@@ -127,30 +126,30 @@ def rdkit_conversion(u, resname):
127
126
"""Converts the solute, `resname`, of the
128
127
:class:`~MDAnalysis.core.universe.Universe` to :class:`rdkit.Chem.rdchem.Mol` object
129
128
for use with a SMARTS selection string to identify dihedral atom groups.
130
-
129
+
131
130
Accepts :class:`~MDAnalysis.core.universe.Universe` object made with
132
131
:func:`~mdpow.workflows.dihedrals.build_universe` and a `resname` as input.
133
132
Uses `resname` to select the solute for conversion by
134
133
:class:`~MDAnalysis.converters.RDKit.RDKitConverter` to :class:`rdkit.Chem.rdchem.Mol`,
135
134
and will add element attributes for Hydrogen if not listed in the topology.
136
-
135
+
137
136
:keywords:
138
-
137
+
139
138
*u*
140
139
:class:`~MDAnalysis.core.universe.Universe` object
141
-
140
+
142
141
*resname*
143
- `resname` for the molecule as defined in
142
+ `resname` for the molecule as defined in
144
143
the topology and trajectory
145
-
144
+
146
145
:returns:
147
-
146
+
148
147
*tuple(mol, solute)*
149
148
function call returns tuple, see below
150
-
149
+
151
150
*mol*
152
151
:class:`rdkit.Chem.rdchem.Mol` object converted from `solute`
153
-
152
+
154
153
*solute*
155
154
molecule specified by :func:`~MDAnalysis.core.groups.select_atoms`
156
155
for :class:`~MDAnalysis.core.universe.Universe` object
@@ -171,8 +170,8 @@ def rdkit_conversion(u, resname):
171
170
def dihedral_indices (dirname , resname , SMARTS = SMARTS_DEFAULT ):
172
171
'''Uses a SMARTS selection string to identify indices for
173
172
relevant dihedral atom groups.
174
-
175
- Requires an MDPOW project directory and `resname`
173
+
174
+ Requires an MDPOW project directory and `resname`
176
175
as input. With :func:`~mdpow.workflows.dihedrals.build_universe` and
177
176
:func:`~mdpow.workflows.dihedrals.rdkit_conversion`, uses the topology
178
177
and trajectory from ``water/Coulomb/0000`` and creates a
@@ -190,16 +189,16 @@ def dihedral_indices(dirname, resname, SMARTS=SMARTS_DEFAULT):
190
189
searches for .gro, .gro.bz2, .gro.gz, and .tpr files for topology,
191
190
and .xtc files for trajectory. It will default to using the tpr file
192
191
available.
193
-
192
+
194
193
*resname*
195
- `resname` for the molecule as defined in
194
+ `resname` for the molecule as defined in
196
195
the topology and trajectory
197
196
198
197
*SMARTS*
199
198
The default SMARTS string is described in detail under :data:`SMARTS_DEFAULT`.
200
-
199
+
201
200
:returns:
202
-
201
+
203
202
*atom_group_indices*
204
203
tuple of tuples of indices for each dihedral atom group
205
204
@@ -209,15 +208,15 @@ def dihedral_indices(dirname, resname, SMARTS=SMARTS_DEFAULT):
209
208
mol = rdkit_conversion (u = u , resname = resname )[0 ]
210
209
pattern = Chem .MolFromSmarts (SMARTS )
211
210
atom_group_indices = mol .GetSubstructMatches (pattern )
212
-
211
+
213
212
return atom_group_indices
214
213
215
214
def dihedral_groups (dirname , resname , SMARTS = SMARTS_DEFAULT ):
216
215
'''Uses the indices of the relevant dihedral atom groups determined
217
216
by :func:`~mdpow.workflows.dihedral.dihedral_indices`
218
217
and returns the names for each atom in each group.
219
-
220
- Requires an MDPOW project directory and `resname`
218
+
219
+ Requires an MDPOW project directory and `resname`
221
220
as input. Expands upon usage of
222
221
:func:`~mdpow.workflows.dihedral.dihedral_indices`
223
222
to return an array of the names of each atom within
@@ -239,14 +238,14 @@ def dihedral_groups(dirname, resname, SMARTS=SMARTS_DEFAULT):
239
238
available.
240
239
241
240
*resname*
242
- `resname` for the molecule as defined in
241
+ `resname` for the molecule as defined in
243
242
the topology and trajectory
244
243
245
244
*SMARTS*
246
245
The default SMARTS string is described in detail under :data:`SMARTS_DEFAULT`.
247
-
246
+
248
247
:returns:
249
-
248
+
250
249
*dihedral_groups*
251
250
list of :func:`numpy.array` for atom names in each dihedral atom group
252
251
@@ -263,12 +262,12 @@ def dihedral_groups(dirname, resname, SMARTS=SMARTS_DEFAULT):
263
262
def dihedral_groups_ensemble (dirname , atom_group_indices ,
264
263
solvents = SOLVENTS_DEFAULT ,
265
264
interactions = INTERACTIONS_DEFAULT ,
266
- start = None , stop = None , step = None ):
265
+ start = None , stop = None , step = None ):
267
266
'''Creates one :class:`~mdpow.analysis.ensemble.Ensemble` for the MDPOW
268
267
project and runs :class:`~mdpow.analysis.dihedral.DihedralAnalysis`
269
268
for each dihedral atom group identified by the SMARTS
270
269
selection string.
271
-
270
+
272
271
.. seealso::
273
272
274
273
:func:`~mdpow.workflows.dihedrals.automated_dihedral_analysis`,
@@ -304,30 +303,30 @@ def dihedral_groups_ensemble(dirname, atom_group_indices,
304
303
.. seealso:: :class:`~mdpow.analysis.ensemble.EnsembleAnalysis`
305
304
306
305
:returns:
307
-
306
+
308
307
*df*
309
308
:class:`pandas.DataFrame` of :class:`~mdpow.analysis.dihedral.DihedralAnalysis`
310
309
results, including all dihedral atom groups for molecule of current project
311
310
312
311
'''
313
312
314
- dih_ens = mdpow . analysis . ensemble .Ensemble (dirname = dirname ,
315
- solvents = solvents ,
316
- interactions = interactions )
313
+ dih_ens = ensemble .Ensemble (dirname = dirname ,
314
+ solvents = solvents ,
315
+ interactions = interactions )
317
316
indices = atom_group_indices
318
317
all_dihedrals = [dih_ens .select_atoms (f'index { i [0 ]} ' ,
319
318
f'index { i [1 ]} ' ,
320
319
f'index { i [2 ]} ' ,
321
320
f'index { i [3 ]} ' ) for i in indices ]
322
321
323
- da = DihedralAnalysis (all_dihedrals )
322
+ da = dihedral . DihedralAnalysis (all_dihedrals )
324
323
da .run (start = start , stop = stop , step = step )
325
324
df = da .results
326
325
327
326
return df
328
327
329
328
def save_df (df , df_save_dir , resname = None , molname = None ):
330
- '''Takes a :class:`pandas.DataFrame` of results from
329
+ '''Takes a :class:`pandas.DataFrame` of results from
331
330
:class:`~mdpow.analysis.dihedral.DihedralAnalysis`
332
331
as input before padding the angles to optionaly save the raw
333
332
data.
@@ -349,13 +348,13 @@ def save_df(df, df_save_dir, resname=None, molname=None):
349
348
optional, path to the location to save results :class:`pandas.DataFrame`
350
349
351
350
*resname*
352
- `resname` for the molecule as defined in
351
+ `resname` for the molecule as defined in
353
352
the topology and trajectory
354
353
355
354
*molname*
356
355
molecule name to be used for labelling
357
356
plots, if different from `resname`
358
-
357
+
359
358
'''
360
359
361
360
df = df .sort_values (by = ["selection" ,
@@ -379,13 +378,13 @@ def save_df(df, df_save_dir, resname=None, molname=None):
379
378
def periodic_angle (df , padding = 45 ):
380
379
'''Pads the angles from the results :class:`~pandas.DataFrame`
381
380
to maintain periodicity in the violin plots.
382
-
381
+
383
382
Takes a :class:`pandas.DataFrame` of results from
384
383
:class:`~mdpow.analysis.dihedral.DihedralAnalysis`
385
384
as input and pads the angles to maintain periodicity
386
385
for properly plotting dihedral angle frequencies as KDE violins
387
386
with :func:`~mdpow.workflows.dihedrals.dihedral_violins`.
388
- Creates two new :class:`pandas.DataFrame` based on the
387
+ Creates two new :class:`pandas.DataFrame` based on the
389
388
cutoff value specified, adds to the angle values, concatenates
390
389
all three :class:`pandas.DataFrame`, maintaining original data and
391
390
adding padding, and returns new augmented :class:`pandas.DataFrame`.
@@ -399,15 +398,15 @@ def periodic_angle(df, padding=45):
399
398
*padding*
400
399
value in degrees
401
400
default: 45
402
-
401
+
403
402
:returns:
404
-
403
+
405
404
*df_aug*
406
405
augmented results :class:`pandas.DataFrame` containing
407
406
padded dihedral angles as specified by `padding`
408
407
409
408
.. rubric:: Example
410
-
409
+
411
410
Typical Workflow::
412
411
413
412
da = DihedralAnalysis(all_dihedrals)
@@ -443,7 +442,7 @@ def dihedral_violins(df, width=0.9, solvents=SOLVENTS_DEFAULT):
443
442
444
443
*solvents*
445
444
The default solvents are documented under :data:`SOLVENTS_DEFAULT`.
446
-
445
+
447
446
:returns:
448
447
449
448
*violin plot*
@@ -468,7 +467,7 @@ def dihedral_violins(df, width=0.9, solvents=SOLVENTS_DEFAULT):
468
467
solv2 = 'octanol'
469
468
if solvs .size > 1 :
470
469
solv2 = solvs [1 ]
471
-
470
+
472
471
g = sns .catplot (data = df , x = "lambda" , y = "dihedral" , hue = "solvent" , col = "interaction" ,
473
472
kind = "violin" , split = True , width = width , inner = None , cut = 0 ,
474
473
linewidth = 0.5 ,
@@ -496,7 +495,7 @@ def dihedral_violins(df, width=0.9, solvents=SOLVENTS_DEFAULT):
496
495
def plot_violins (df , resname , figdir = None , molname = None , width = 0.9 , solvents = SOLVENTS_DEFAULT ):
497
496
'''Coordinates plotting and optionally saving figures for all dihedral
498
497
atom groups.
499
-
498
+
500
499
Makes a subdirectory within the specified
501
500
`figdir` using `resname` or `molname` provided and saves violin plot
502
501
figur for each dihedral atom group separately.
@@ -505,15 +504,15 @@ def plot_violins(df, resname, figdir=None, molname=None, width=0.9, solvents=SOL
505
504
506
505
:func:`~mdpow.workflows.dihedrals.automated_dihedral_analysis`,
507
506
:func:`~mdpow.workflows.dihedrals.dihedral_violins`
508
-
507
+
509
508
:keywords:
510
-
509
+
511
510
*df*
512
511
augmented results :class:`pandas.DataFrame` from
513
512
:func:`~mdpow.workflows.dihedrals.periodic_angle`
514
513
515
514
*resname*
516
- `resname` for the molecule as defined in
515
+ `resname` for the molecule as defined in
517
516
the topology and trajectory
518
517
519
518
*figdir*
@@ -575,7 +574,7 @@ def automated_dihedral_analysis(dirname=None, df_save_dir=None, figdir=None,
575
574
'''Runs :class:`~mdpow.analysis.dihedral.DihedralAnalysis` for a single MDPOW
576
575
project and creates violin plots of dihedral angle frequencies for each
577
576
relevant dihedral atom group.
578
-
577
+
579
578
For one MDPOW project, automatically determines all relevant dihedral atom groups
580
579
in the molecule, runs :class:`~mdpow.analysis.dihedral.DihedralAnalysis` for each group,
581
580
pads the dihedral angles from analysis results for all groups to maintain periodicity,
@@ -605,13 +604,13 @@ def automated_dihedral_analysis(dirname=None, df_save_dir=None, figdir=None,
605
604
optional, path to the location to save figures
606
605
607
606
*resname*
608
- `resname` for the molecule as defined in
607
+ `resname` for the molecule as defined in
609
608
the topology and trajectory
610
609
611
610
*molname*
612
611
molecule name to be used for labelling
613
612
plots, if different from `resname`
614
-
613
+
615
614
*SMARTS*
616
615
The default SMARTS string is described in detail under :data:`SMARTS_DEFAULT`.
617
616
@@ -652,7 +651,7 @@ def automated_dihedral_analysis(dirname=None, df_save_dir=None, figdir=None,
652
651
relevant dihedral atom group in the molecule from the current MDPOW project
653
652
654
653
.. rubric:: Example
655
-
654
+
656
655
Typical Workflow::
657
656
658
657
import automated_dihedral_analysis as ada
0 commit comments