Skip to content

Commit

Permalink
Merge pull request #120 from marrink-lab/fix-log
Browse files Browse the repository at this point in the history
Minor fixes about logging
  • Loading branch information
pckroon committed Sep 26, 2018
2 parents 5d9daf0 + 05b3436 commit 544b61f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
15 changes: 13 additions & 2 deletions bin/martinize2
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ from vermouth.dssp.dssp import (
AnnotateResidues,
)
from vermouth.log_helpers import (StyleAdapter, BipolarFormatter,
CountingHandler)
CountingHandler, TypeAdapter)
from vermouth import selectors
from vermouth.map_input import (
read_mapping_directory,
Expand All @@ -46,7 +46,7 @@ from vermouth.map_input import (
# TODO Since vermouth's __init__.py does some logging (KDTree), this may or may
# not work as intended. Investigation required.

LOGGER = logging.getLogger('vermouth')
LOGGER = TypeAdapter(logging.getLogger('vermouth'))

PRETTY_FORMATTER = logging.Formatter(fmt='{levelname:>8} - {type} - {message}',
style='{')
Expand Down Expand Up @@ -99,13 +99,16 @@ def pdb_to_universal(system, delete_unknown=False,
"""
canonicalized = system.copy()
canonicalized.force_field = force_field
LOGGER.info('Guessing the bonds.', type='step')
vermouth.MakeBonds().run_system(canonicalized)
if write_graph is not None:
vermouth.pdb.write_pdb(canonicalized, str(write_graph), omit_charges=True)
LOGGER.info('Repairing the graph.', type='step')
vermouth.RepairGraph(delete_unknown=delete_unknown).run_system(canonicalized)
if write_repair is not None:
vermouth.pdb.write_pdb(canonicalized, str(write_repair),
omit_charges=True, nan_missing_pos=True)
LOGGER.info('Dealing with modifications.', type='step')
vermouth.CanonicalizeModifications().run_system(canonicalized)
if write_canon is not None:
vermouth.pdb.write_pdb(canonicalized, str(write_canon),
Expand All @@ -118,13 +121,18 @@ def martinize(system, mappings, to_ff, delete_unknown=False):
"""
Convert a system from one force field to an other at lower resolution.
"""
LOGGER.info('Creating the graph at the target resolution.', type='step')
vermouth.DoMapping(mappings=mappings,
to_ff=to_ff,
delete_unknown=delete_unknown,
attribute_keep=('cgsecstruct', )).run_system(system)
LOGGER.info('Averaging the coordinates.', type='step')
vermouth.DoAverageBead(ignore_missing_graphs=True).run_system(system)
LOGGER.info('Applying the blocks.', type='step')
vermouth.ApplyBlocks().run_system(system)
LOGGER.info('Applying the links.', type='step')
vermouth.DoLinks().run_system(system)
LOGGER.info('Placing the charge dummies.', type='step')
vermouth.LocateChargeDummies().run_system(system)
return system

Expand Down Expand Up @@ -418,6 +426,7 @@ def entry():

# Apply a rubber band elastic network is required.
if args.elastic:
LOGGER.info('Setting the rubber bands.', type='step')
if args.rb_selection is not None:
selector = functools.partial(
selectors.proto_select_attribute_in,
Expand All @@ -439,6 +448,7 @@ def entry():

# Apply position restraints if required.
if args.posres != 'none':
LOGGER.info('Applying position restraints.', type='step')
node_selectors = {'all': selectors.select_all,
'backbone': selectors.select_backbone}
node_selector = node_selectors[args.posres]
Expand All @@ -449,6 +459,7 @@ def entry():
for chain_set in args.merge_chains:
vermouth.MergeChains(chain_set).run_system(system)

LOGGER.info('Writing output.', type='step')
# Write the topology if requested
header = [
'This file was generated using the following command:',
Expand Down
3 changes: 3 additions & 0 deletions vermouth/log_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ def log(self, level, msg, *args, **kwargs):
else:
self.logger.log(level, msg, *args, **kwargs)

def addHandler(self, *args, **kwargs):
self.logger.addHandler(*args, **kwargs)


class StyleAdapter(PassingLoggerAdapter):
"""
Expand Down
2 changes: 1 addition & 1 deletion vermouth/processors/repair_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def make_reference(mol):
# TODO: matches is sorted by isomorphism. So we should probably use
# that with e.g. itertools.takewhile.
if not matches:
LOGGER.error("Can't find isomorphism between {}{} and it's "
LOGGER.error("Can't find isomorphism between {}{} and its "
"reference.", resname, resid, type='inconsistent-data')
continue

Expand Down

0 comments on commit 544b61f

Please sign in to comment.