Skip to content

Commit

Permalink
Code smells removed
Browse files Browse the repository at this point in the history
  • Loading branch information
hlasimpk committed Apr 24, 2017
1 parent 0687468 commit c86374d
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 210 deletions.
2 changes: 1 addition & 1 deletion simbad/command_line/simbad_contaminant.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def main():
args = p.parse_args()

if args.work_dir:
logging.info('Making a named work directory: {0}'.format(args.work_dir))
logging.info('Making a named work directory: %s' % args.work_dir)
try:
os.mkdir(args.work_dir)
except:
Expand Down
28 changes: 15 additions & 13 deletions simbad/lattice/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ def __repr__(self):
def _as_dict(self):
"""Convert the :obj:`_LatticeParameterScore <simbad.lattice.search._LatticeParameterScore>`
object to a dictionary"""
dict = {}
dictionary = {}
for k in self.__slots__:
if k == 'unit_cell':
dict['a'], dict['b'], dict['c'], dict['alpha'], dict['beta'], dict['gamma'] = self.unit_cell
dictionary['a'], dictionary['b'], dictionary['c'], dictionary['alpha'], dictionary['beta'], \
dictionary['gamma'] = self.unit_cell
else:
dict[k] = getattr(self, k)
return dict
dictionary[k] = getattr(self, k)
return dictionary


class LatticeSearch(object):
Expand Down Expand Up @@ -75,6 +76,7 @@ class LatticeSearch(object):
and write the same information to a comma-separated file called ``lattice.csv``.
"""

def __init__(self, unit_cell, space_group, lattice_db_fname, max_to_keep=20):
"""Initialize a new Lattice Search class
Expand Down Expand Up @@ -159,7 +161,7 @@ def space_group(self, space_group):
elif space_group == "C4212":
space_group = "P422"
self._space_group = space_group
self._search_results = None
self._search_results = None

@property
def total_db_files(self):
Expand All @@ -182,16 +184,16 @@ def unit_cell(self, unit_cell):
msg = "Unit cell parameters need to be of type str, list or tuple"
raise TypeError(msg)
self._unit_cell = unit_cell
self._search_results = None
self._search_results = None

def copy_results(self, pdb_db, dir=os.getcwd()):
def copy_results(self, pdb_db, directory=os.getcwd()):
"""Copy the results from a local copy of the PDB
Parameters
----------
pdb_db : str
The path to the local copy of the PDB
dir : str
directory : str
The path to save results to [default: .]
Raises
Expand All @@ -207,7 +209,7 @@ def copy_results(self, pdb_db, dir=os.getcwd()):
msg = "No search results found/available"
raise ValueError(msg)

out_dir = os.path.join(dir, 'lattice_input_models')
out_dir = os.path.join(directory, 'lattice_input_models')
if not os.path.isdir(out_dir):
os.mkdir(out_dir)
else:
Expand All @@ -222,12 +224,12 @@ def copy_results(self, pdb_db, dir=os.getcwd()):
with open(f_name_out, 'w') as f_out:
f_out.write(f_in.read())

def download_results(self, dir=os.getcwd()):
def download_results(self, directory=os.getcwd()):
"""Download the results directly from the PDB
Parameters
----------
dir : str
directory : str
The path to save results to [default: .]
Raises
Expand All @@ -243,7 +245,7 @@ def download_results(self, dir=os.getcwd()):
msg = "No search results found/available"
raise ValueError(msg)

out_dir = os.path.join(dir, 'lattice_input_models')
out_dir = os.path.join(directory, 'lattice_input_models')
if not os.path.isdir(out_dir):
os.mkdir(out_dir)
else:
Expand All @@ -261,7 +263,6 @@ def download_results(self, dir=os.getcwd()):
os.path.join(out_dir, '{0}.pdb'.format(result.pdb_code))
)


def search(self, tolerance=0.05):
"""Search for similar Niggli cells
Expand Down Expand Up @@ -361,6 +362,7 @@ def calculate_penalty(query, reference):
-------
"""

def penalty(q, r):
delta = abs(numpy.asarray(q, dtype=numpy.float64) - numpy.asarray(r, dtype=numpy.float64))
return delta[:3].sum().item(), delta[3:].sum().item()
Expand Down
80 changes: 0 additions & 80 deletions simbad/parsers/database_parser.py

This file was deleted.

19 changes: 9 additions & 10 deletions simbad/util/config_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def _process_options(self):

def _preset_options(self, mode):
assert hasattr(self, mode), "Unknown mode: {0}".format(mode)
logger.info("Using preset mode: {0}".format(mode))
logger.info("Using preset mode: %s" % mode)
for k, v in getattr(self, mode).iteritems():
if 'cmdline_flags' in self.d and k in self.d['cmdline_flags']:
if self.d[k] == v:
Expand All @@ -131,10 +131,10 @@ def _preset_options(self, mode):
msg = 'WARNING! Overridng {0} setting: {1} => {2} with {3}'.format(mode, k, v, self.d[k])
logger.critical(msg)
elif k in self.d:
logger.debug("{0} overriding default setting: {1} => {2} with {3}".format(mode, k, v, self.d[k]))
logger.debug("%s overriding default setting: %s => %s with %s" % mode, k, v, self.d[k])
self.d[k] = v
else:
logger.debug("{0} setting: {1} => {2}".format(mode, k, v))
logger.debug("%s setting: %s => %s" % mode, k, v)
self.d[k] = v
return

Expand All @@ -146,7 +146,7 @@ def _read_config_file(self, config_file):

for section in config.sections():

if not section in _SECTIONS_REFERENCE:
if section not in _SECTIONS_REFERENCE:
_SECTIONS_REFERENCE[section] = []

# Basic switch statement to determine the type of variable
Expand Down Expand Up @@ -178,12 +178,11 @@ def _read_config_file(self, config_file):
else:
self.d[k] = v

_SECTIONS_REFERENCE[section].append(k)
_SECTIONS_REFERENCE[section].append(k)

return

def _read_cmdline_opts(self, cmdline_opts):
tmpv = None
cmdline_flags = []

for k, v in cmdline_opts.iteritems():
Expand All @@ -198,8 +197,8 @@ def _read_cmdline_opts(self, cmdline_opts):

if k not in self.d:
self.d[k] = v
elif v != None:
logger.debug("Cmdline setting {0}: {1} => {2}".format(k, self.d[k], v))
elif v is not None:
logger.debug("Cmdline setting %s: %s => %s" % k, self.d[k], v)
self.d[k] = v

self.d['cmdline_flags'] = cmdline_flags
Expand All @@ -209,7 +208,7 @@ def _isfloat(self, value):
try:
float(value)
return True
except:
except ValueError:
return False

def prettify_parameters(self):
Expand All @@ -230,7 +229,7 @@ def write_config_file(self, config_file=None):
config_file = os.path.join(self.d['work_dir'], self.d['name'] + ".ini")
# Write config to job specific directory
self.d["out_config_file"] = config_file
logger.info("SIMBAD configuration written to: {0}".format(config_file))
logger.info("SIMBAD configuration written to: %s" % config_file)
with open(config_file, "w") as out: config.write(out)
return

Expand Down
14 changes: 7 additions & 7 deletions simbad/util/mr_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ def __repr__(self):
def _as_dict(self):
"""Convert the :obj:`_MrScore <simbad.util.mr_util._MrScore>`
object to a dictionary"""
dict = {}
dictionary = {}
for k in self.__slots__:
dict[k] = getattr(self, k)
return dict
dictionary[k] = getattr(self, k)
return dictionary


class MrSubmit(object):
Expand Down Expand Up @@ -268,7 +268,7 @@ def suppress_stdout(self):

def _run_job(self, model):
"""Function to run MR on each model"""
logger.info("Running MR and refinement on {0}".format(model.pdb_code))
logger.info("Running MR and refinement on %s" % model.pdb_code)

# Generate MR input file
self.MR_setup(model)
Expand Down Expand Up @@ -495,7 +495,7 @@ def run(job_queue):
print "MR with {0} was successful so removing remaining jobs from inqueue".format(model.pdb_code)
while not job_queue.empty():
job = job_queue.get()
logger.debug("Removed job [{0}] from inqueue".format(job.pdb_code))
logger.debug("Removed job [%s] from inqueue" %s job.pdb_code)

# Create job queue
job_queue = multiprocessing.Queue()
Expand Down Expand Up @@ -530,7 +530,7 @@ def run(job_queue):
final_r_free = RP.finalRfree
final_r_fact = RP.finalRfact

if self._dano != None:
if self._dano is not None:
AS = anomalous_util.AnomSearch(self.mtz, self.output_dir, self.mr_program)
AS.run(result)
a = AS.search_results()
Expand Down Expand Up @@ -589,7 +589,7 @@ def run(job_queue):
final_r_free = RP.finalRfree
final_r_fact = RP.finalRfact

if self._dano != None:
if self._dano is not None:
AS = anomalous_util.AnomSearch(self.mtz, self.output_dir, self.mr_program)
AS.run(result)
a = AS.search_results()
Expand Down

0 comments on commit c86374d

Please sign in to comment.