Skip to content

Commit 7e43245

Browse files
committed
Linting with flake8
1 parent 0509c8b commit 7e43245

File tree

6 files changed

+165
-165
lines changed

6 files changed

+165
-165
lines changed

PyCEC/__init__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
PyCEC: A Python implementation of the Center of Excess Charge (CEC) collective variable.
2+
PyCEC: A Python implementation of the Center of Excess Charge (CEC) CV.
33
================================================
44
55
Documentation is available in the docstrings and
@@ -27,18 +27,17 @@
2727
test --- Run PyCEC unittests
2828
"""
2929

30-
#export PYTHONPATH="${PYTHONPATH}:/biggin/b222/catz0163/pept/dynamics/pept_holo/pept_AF_H87P_D342P_v2/qmmm/analysis/PyCEC/PyCEC"
31-
3230
# # For relative imports to work in Python 3.6
3331
# import os, sys; sys.path.append(os.path.dirname(os.path.realpath(__file__)))
3432

3533
from pathlib import Path
3634

35+
3736
def _get_version() -> str:
3837
"""Read VERSION.txt and return its contents."""
3938
path = Path(__file__).parent.resolve()
4039
version_file = path / "VERSION.txt"
4140
return version_file.read_text(encoding="utf-8").strip()
4241

4342

44-
__version__ = _get_version()
43+
__version__ = _get_version()

PyCEC/analysis/analysis.py

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
from PyCEC.cec_system import CECSystem
33

44
# MDAnalysis
5-
import MDAnalysis as mda # TODO: This needs to be fixed tbh, not efficient
5+
import MDAnalysis as mda # TODO: This needs to be fixed tbh, not efficient
66
from MDAnalysis.analysis.hydrogenbonds.hbond_analysis import HydrogenBondAnalysis as HBA
77

88
from tqdm import tqdm
9-
import time
109

1110
from matplotlib import pyplot as plt
1211
import numpy as np
@@ -16,9 +15,9 @@ class CVAnalysis:
1615
"""
1716
Class to analyse the collective variable of the CEC system.
1817
"""
19-
20-
def __init__(self, universe, initial_resid, target_resid, other_resids=None,
21-
ligand=None, cyzone_dim=[8, 8, -8], frame_n=0):
18+
def __init__(self, universe, initial_resid, target_resid,
19+
other_resids=None, ligand=None, cyzone_dim=[8, 8, -8],
20+
frame_n=0):
2221
# Attributes
2322
self.u = universe
2423
self.initial_resid = initial_resid
@@ -40,31 +39,29 @@ def __init__(self, universe, initial_resid, target_resid, other_resids=None,
4039
def get_traj_times(self):
4140
"""
4241
Get the time of each frame in the trajectory.
43-
42+
4443
"""
4544
times = []
4645
for ts in self.u.trajectory:
4746
times.append(ts.time)
4847

4948
return times
5049

51-
5250
def get_water_counts(self):
5351
"""
5452
Iterate through the frames and get the water counts.
55-
53+
5654
"""
5755
water_counts = []
58-
for ts in tqdm(self.u.trajectory, desc="Getting water counts..."): # tqdm progress bar
56+
for ts in tqdm(self.u.trajectory, desc="Getting water counts..."):
5957
self.cv.set_frame(ts.frame)
6058
water_counts.append(len(self.cv.waters.atoms))
6159

6260
return water_counts
6361

64-
6562
def get_water_counts_h(self):
6663
"""
67-
Iterate through the frames and get the water counts in a readable format.
64+
Iterate through the frames and get water counts in a readable format.
6865
6966
"""
7067
water_counts = self.get_water_counts()
@@ -78,7 +75,7 @@ def get_water_counts_h(self):
7875
for i, t, w in water_c:
7976
print(f"Frame {i} at time {t} ps has {w} water molecules.")
8077

81-
#return water_c
78+
# return water_c
8279

8380

8481
class WaterAnalysis:
@@ -94,7 +91,7 @@ def __init__(self, universe, initial_resid, target_resid, other_resids,
9491
self.other_resids = other_resids
9592
self.ligand = ligand
9693
self.cyzone_dim = cyzone_dim
97-
self.frame_n = frame_n # TODO: is frame relevant here?
94+
self.frame_n = frame_n # TODO: is frame relevant here?
9895

9996
# Trajectory information
10097
self.n_frames = len(self.u.trajectory)
@@ -109,39 +106,37 @@ def __init__(self, universe, initial_resid, target_resid, other_resids,
109106
self.waters = self.cv.waters
110107
self.waters_sele_str = self.cv.waters_sele_str
111108

112-
113109
def get_traj_times(self):
114110
"""
115111
Get the time of each frame in the trajectory.
116-
112+
117113
"""
118114
times = []
119115
for ts in self.u.trajectory:
120116
times.append(ts.time)
121117

122118
return times
123119

124-
def get_hydrogen_bonds(self, donors_sel=None, hydrogens_sel=None, acceptors_sel=None,
125-
distance_cutoff=3.5, angle_cutoff=120.0):
120+
def get_hydrogen_bonds(self, donors_sel=None, hydrogens_sel=None,
121+
acceptors_sel=None, distance_cutoff=3.5,
122+
angle_cutoff=120.0):
126123
"""
127124
Get the hydrogen bonds between the a pair of molecules.
128-
125+
129126
"""
130127
# Create the HBA object
131128
hba = HBA(universe=self.u, donors_sel=donors_sel,
132129
hydrogens_sel=hydrogens_sel, acceptors_sel=acceptors_sel,
133130
d_h_cutoff=distance_cutoff, d_h_a_angle_cutoff=angle_cutoff)
134-
hba.run() # run the analysis
131+
hba.run() # run the analysis
135132

136133
# Get counts
137134
counts = hba.count_by_time()
138-
139-
return counts
140-
135+
141136
def get_water_h_bonds(self, distance_cutoff=3.5, angle_cutoff=120.0):
142137
"""
143138
Get the hydrogen bonds between the water molecules.
144-
139+
145140
"""
146141
# Get the hydrogen bonds
147142
counts = self.get_hydrogen_bonds(donors_sel=self.waters_sele_str,
@@ -150,30 +145,29 @@ def get_water_h_bonds(self, distance_cutoff=3.5, angle_cutoff=120.0):
150145
distance_cutoff=distance_cutoff,
151146
angle_cutoff=angle_cutoff)
152147
return counts
153-
148+
154149
def plot_hbond_counts(self, counts, save=False):
155150
"""
156151
Plot the hydrogen bond counts.
157-
152+
158153
"""
159154
fig, ax = plt.subplots()
160155
ax.plot(self.times, counts)
161156
ax.set_ylabel("Number of hydrogen bonds")
162157
ax.set_xlabel("Frame number")
163158
ax.set_title("Hydrogen bond counts over time")
164-
159+
165160
if save:
166161
fig.savefig("hbond_counts.png", dpi=300)
167-
168-
plt.show()
169162

163+
plt.show()
170164

171165
def get_max_hbond_counts(self, counts):
172166
"""
173167
Get the frames and times of the 10 frames with the most hydrogen bonds.
174168
"""
175169
# Get the frames with the most hydrogen bonds
176-
max_counts = sorted(counts, reverse=True)[:10] # get the 10 highest counts
170+
max_counts = sorted(counts, reverse=True)[:10] # get 10 highest counts
177171
print(f"\nMax counts: {max_counts}")
178172
max_frames = []
179173
for c in max_counts:
@@ -184,7 +178,7 @@ def get_max_hbond_counts(self, counts):
184178
print(f"Times of the frames with the most hydrogen bonds: {max_times}")
185179

186180
return max_frames, max_times
187-
181+
188182
def find_consistent_waters(self):
189183
"""
190184
Find waters consistently included in the waters list.
@@ -198,8 +192,6 @@ def get_residence_times(self):
198192
pass
199193

200194

201-
202-
203195
if __name__ == "__main__":
204196

205197
# Directory and title
@@ -225,4 +217,4 @@ def get_residence_times(self):
225217

226218
counts = wa.get_water_h_bonds()
227219

228-
wa.plot_hbond_counts(counts, save=True)
220+
wa.plot_hbond_counts(counts, save=True)

PyCEC/analysis/plotting.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
from PyCEC.cec_system import CECSystem
21
from PyCEC.analysis.analysis import CVAnalysis
32

43
import matplotlib.pyplot as plt
54
import numpy as np
6-
import os
7-
import pandas as pd
8-
9-
from tqdm import tqdm
105

116
import MDAnalysis as mda
127

@@ -41,12 +36,14 @@ def plot_water_counts(self, save=False):
4136

4237
plt.show()
4338

44-
def plot_water_counts_line(self, save=False, filename='water_counts_line_hist', test=False, show=False):
45-
"""
46-
Plot the water counts over time, with a histogram of frequency to the right of the main plot.
47-
39+
def plot_water_counts_line(self, save=False,
40+
filename='water_counts_line_hist',
41+
test=False, show=False):
4842
"""
43+
Plot the water counts over time, with a histogram of frequency to the\
44+
right of the main plot.
4945
46+
"""
5047
if test:
5148
# Generate some random data
5249
water_counts = np.random.randint(0, 100, self.cv_analysis.n_frames)
@@ -55,7 +52,10 @@ def plot_water_counts_line(self, save=False, filename='water_counts_line_hist',
5552
water_counts = self.cv_analysis.get_water_counts()
5653

5754
# Create a figure and a grid of subplots
58-
fig, axs = plt.subplots(1, 2, gridspec_kw={'width_ratios': [4, 1], 'wspace': 0.02}, figsize=(10, 5))
55+
fig, axs = plt.subplots(1, 2,
56+
gridspec_kw={'width_ratios': [4, 1],
57+
'wspace': 0.02},
58+
figsize=(10, 5))
5959

6060
# Line plot on the left
6161
axs[0].plot(self.cv_analysis.times, water_counts, c='b', dash_capstyle='round')
@@ -65,8 +65,9 @@ def plot_water_counts_line(self, save=False, filename='water_counts_line_hist',
6565
axs[0].ticklabel_format(style='plain')
6666

6767
# Histogram on the right
68-
axs[1].hist(water_counts, bins=self.cv_analysis.n_frames//10, orientation='horizontal',
69-
color='b', edgecolor='white', lw=0.4)
68+
axs[1].hist(water_counts, bins=self.cv_analysis.n_frames//10,
69+
orientation='horizontal', color='b', edgecolor='white',
70+
lw=0.4)
7071
axs[1].axis('off')
7172

7273
# Adjust layout to prevent overlap
@@ -80,11 +81,10 @@ def plot_water_counts_line(self, save=False, filename='water_counts_line_hist',
8081
if show:
8182
plt.show()
8283

83-
8484
def plot_water_counts_boxplot(self, save=False):
8585
"""
8686
Plot the boxplot of water counts.
87-
87+
8888
"""
8989
water_counts = self.cv_analysis.get_water_counts()
9090

@@ -101,7 +101,7 @@ def plot_water_counts_boxplot(self, save=False):
101101
def plot_water_counts_violinplot(self, save=False):
102102
"""
103103
Plot the violin plot of water counts.
104-
104+
105105
"""
106106
water_counts = self.cv_analysis.get_water_counts()
107107

@@ -126,12 +126,11 @@ def plot_water_counts_violinplot(self, save=False):
126126

127127
# Initialise class
128128
cv_analysis = CVAnalysis(u1, initial_resid=342, target_resid=56,
129-
other_resids=[53, 57, 61, 622],
130-
ligand=[1, 2], cyzone_dim=[8, 8, -8],
131-
frame_n=160)
129+
other_resids=[53, 57, 61, 622], ligand=[1, 2],
130+
cyzone_dim=[8, 8, -8], frame_n=160)
132131

133132
# Create the CVPlotting object
134133
cv_plotting = CVPlotting(cv_analysis)
135134

136135
# Plot the water counts over time
137-
cv_plotting.plot_water_counts_line(save=True, test=True)
136+
cv_plotting.plot_water_counts_line(save=True, test=True)

0 commit comments

Comments
 (0)