Skip to content

Commit

Permalink
Add verbose keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
gitesei committed Nov 4, 2024
1 parent 2744e6d commit 045ef70
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
13 changes: 8 additions & 5 deletions FRETpredict/FRET.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,13 @@ def __init__(self, protein, residues, **kwargs):
self.weights = kwargs.get('weights', False)
self.user_weights = kwargs.get('user_weights', None)
self.stdev = kwargs.get('filter_stdev', 0.02)
self.verbose = kwargs.get('verbose', False)

# Logging set up
logging.basicConfig(filename=kwargs.get('log_file', 'log'), level=logging.INFO)
if self.verbose:
logging.basicConfig(filename=kwargs.get('log_file', 'log'), level=logging.INFO)
else:
logging.basicConfig(filename=kwargs.get('log_file', 'log'), level=logging.DEBUG)

# Write the string for the placement residues selection
for i in range(2):
Expand Down Expand Up @@ -420,7 +424,7 @@ def trajectoryAnalysis(self):
# If dyes pair has no spectral overlap, skip iteration
if self.r0 == 0:

print('\nDyes pair R0 = 0!')
logging.debug('Dyes pair R0 = 0!')
continue

# Calculate (r/r0)^6 factor for FRET efficiency calculations
Expand Down Expand Up @@ -583,7 +587,6 @@ def save(self, **kwargs):
# k2, Static, Dynamic1, and Dynamic2 averaging
# Create DataFrame if only one value of k2 is present (only 1 protein structure/frame provided)
if k2.size == 1:

df = pd.Series([k2, estatic, edynamic1, edynamic2], index=['k2', 'Estatic', 'Edynamic1', 'Edynamic2'])

# Create DataFrame of weighted averaged values
Expand All @@ -595,7 +598,7 @@ def save(self, **kwargs):
self.weightedAvgSDSE(edynamic2[np.isfinite(k2)], self.weights[np.isfinite(k2)])],
columns=['Average', 'SD', 'SE'], index=['k2', 'Estatic', 'Edynamic1', 'Edynamic2'])

print(f'Effective fraction of frames contributing to average: {self.fraction_frames()}')
logging.debug(f'Effective fraction of frames contributing to average: {self.fraction_frames()}')

# Save DataFrame in pickle format
df.to_pickle(output_reweight_prefix + '-data-{:d}-{:d}.pkl'.format(self.residues[0], self.residues[1]))
Expand Down Expand Up @@ -644,4 +647,4 @@ def run(self):
# Calculate k2 distribution and k2, Static, Dynamic1, Dynamic2 averaging. Save data to file.
self.save()

print('\nDone.')
logging.info('Done')
10 changes: 3 additions & 7 deletions FRETpredict/libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#: Name of the directory in the package that contains the library data.
LIBDIR = "lib"


def find_file(filename, pkglibdir=LIBDIR):

"""
Expand Down Expand Up @@ -116,18 +115,16 @@ def __init__(self, name):
self.lib['filename'] = find_file(self.lib['filename'][:-2] + name.split(' cutoff')[1])

# Print logging information
logger.debug("[rotamers] ensemble {:s} with topology {:s}.pdb".format(self.lib['filename'],
logger.info("[rotamers] ensemble {:s} with topology {:s}.pdb".format(self.lib['filename'],
self.lib['filename'].split('_cutoff')[0]))
logger.debug("[rotamers] populations {:s}".format(self.lib['filename'] + '_weights.txt'))
logger.info("[rotamers] populations {:s}".format(self.lib['filename'] + '_weights.txt'))

# If trajectory is not found
if not os.path.isfile(self.lib['filename'] + '.dcd'):

raise ValueError("No trajectory named {0}.dcd".format(self.lib['filename']))

# If weights are not found
if not os.path.isfile(self.lib['filename'] + '_weights.txt'):

raise ValueError("No file named {0}_weights.txt".format(self.lib['filename'] + '_weights.txt'))

# Rotamers parameters
Expand Down Expand Up @@ -161,5 +158,4 @@ def __repr__(self):
"""

return "<RotamerLibrary '{0}' by {1} with {2} rotamers>".format(self.name, self.lib['author'],
len(self.weights) - 2)
return "<RotamerLibrary '{0}' by {1} with {2} rotamers>".format(self.name, self.lib['author'], len(self.weights) - 2)
11 changes: 6 additions & 5 deletions FRETpredict/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,11 @@ def rotamer_placement(self, universe, prot_atoms, lib):
universe.load_new(probe_coords, format=MemoryReader, order='afc')

# Save aligned rotamers
rotamers = universe.select_atoms("all")
with MDAnalysis.Writer(lib.name + ".pdb", rotamers.n_atoms) as W:
for ts in universe.trajectory:
W.write(rotamers)
if self.verbose:
rotamers = universe.select_atoms("all")
with MDAnalysis.Writer(lib.name.replace(' ','_')+'.pdb', rotamers.n_atoms) as W:
for ts in universe.trajectory:
W.write(rotamers)

return universe

Expand Down Expand Up @@ -491,7 +492,7 @@ def calculate_ws(self):
skip_footer=0,
delimiter=' ')

# Check if single-frame structure
# Check if single-frame structure
if np.shape(Z) == (2,):

w_s = np.array([1.0])
Expand Down

0 comments on commit 045ef70

Please sign in to comment.