Skip to content

Commit

Permalink
Setting nproc in the class attribute now
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthijs Tadema authored and Matthijs Tadema committed Mar 4, 2020
1 parent 9a16394 commit eba1107
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
12 changes: 8 additions & 4 deletions bin/martinize2
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ from vermouth.map_input import (
combine_mappings
)

from vermouth.processors.processor import Processor

# TODO Since vermouth's __init__.py does some logging (KDTree), this may or may
# not work as intended. Investigation required.

Expand Down Expand Up @@ -95,7 +97,7 @@ def read_system(path, ignore_resnames=(), ignh=None, modelidx=None):

def pdb_to_universal(system, delete_unknown=False, force_field=None,
bonds_from_name=True, bonds_from_dist=True, bonds_fudge=1,
write_graph=None, write_repair=None, write_canon=None, nproc=1):
write_graph=None, write_repair=None, write_canon=None):
"""
Convert a system read from the PDB to a clean canonical atomistic system.
"""
Expand All @@ -106,7 +108,7 @@ def pdb_to_universal(system, delete_unknown=False, force_field=None,
LOGGER.info('Guessing the bonds.', type='step')
vermouth.MakeBonds(allow_name=bonds_from_name,
allow_dist=bonds_from_dist,
fudge=bonds_fudge, nproc=nproc).run_system(canonicalized)
fudge=bonds_fudge).run_system(canonicalized)
vermouth.MergeNucleicStrands().run_system(canonicalized)
if write_graph is not None:
vermouth.pdb.write_pdb(canonicalized, str(write_graph), omit_charges=True)
Expand Down Expand Up @@ -402,6 +404,9 @@ def entry():
'multiple times.', default=0)

args = parser.parse_args()

Processor.nproc = args.nproc

if args.elastic and args.govs_includes:
parser.error('A rubber band elastic network and GoMartini are not '
'compatible. The -elastic and -govs-include flags cannot '
Expand Down Expand Up @@ -496,8 +501,7 @@ def entry():
bonds_fudge=args.bonds_fudge,
write_graph=args.write_graph,
write_repair=args.write_repair,
write_canon=args.write_canon,
nproc=args.nproc
write_canon=args.write_canon
)

LOGGER.info('Read input.', type='step')
Expand Down
5 changes: 2 additions & 3 deletions vermouth/processors/make_bonds.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,10 @@ def make_bonds(molecule, allow_name=True, allow_dist=True, fudge=1.0):


class MakeBonds(Processor):
def __init__(self, allow_name=True, allow_dist=True, fudge=1, nproc=1):
def __init__(self, allow_name=True, allow_dist=True, fudge=1):
self.allow_name = allow_name
self.allow_dist = allow_dist
self.fudge = fudge
self.nproc = nproc

def run_system(self, system):
if not system.molecules:
Expand All @@ -293,7 +292,7 @@ def run_system(self, system):
for mol_idx, molecule in enumerate(system.molecules):
nx.set_node_attributes(molecule, mol_idx, 'mol_idx')
# If using multiple processors, run the system normally
if hasattr(self, 'nproc') and self.nproc > 1:
if self.nproc > 1:
super().run_system(system)
# If not using multiple processors, compose molecules into one
else:
Expand Down

0 comments on commit eba1107

Please sign in to comment.