diff --git a/FRETpredict/FRET.py b/FRETpredict/FRET.py index 4462bee..597616d 100644 --- a/FRETpredict/FRET.py +++ b/FRETpredict/FRET.py @@ -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): @@ -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 @@ -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 @@ -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])) @@ -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') diff --git a/FRETpredict/libraries.py b/FRETpredict/libraries.py index 1dc6d63..f82caac 100644 --- a/FRETpredict/libraries.py +++ b/FRETpredict/libraries.py @@ -22,7 +22,6 @@ #: Name of the directory in the package that contains the library data. LIBDIR = "lib" - def find_file(filename, pkglibdir=LIBDIR): """ @@ -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 @@ -161,5 +158,4 @@ def __repr__(self): """ - return "".format(self.name, self.lib['author'], - len(self.weights) - 2) + return "".format(self.name, self.lib['author'], len(self.weights) - 2) diff --git a/FRETpredict/utils.py b/FRETpredict/utils.py index 5d55962..8d9710b 100644 --- a/FRETpredict/utils.py +++ b/FRETpredict/utils.py @@ -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 @@ -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])