Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makebonds molecule #234

Closed
wants to merge 11 commits into from
Next Next commit
Added multiprocessing to run_system method of Processor class
  • Loading branch information
Matthijs Tadema authored and Matthijs Tadema committed Mar 4, 2020
commit 98033eac124306225144ac3a91ac11db89678d0a
19 changes: 14 additions & 5 deletions vermouth/processors/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"""
Provides an abstract base class for processors.
"""

import multiprocessing
import functools

class Processor:
"""
Expand All @@ -32,10 +33,18 @@ def run_system(self, system):
system: vermouth.system.System
The system to process. Is modified in-place.
"""
mols = []
for molecule in system.molecules:
mols.append(self.run_molecule(molecule))
system.molecules = mols
if self.nproc and self.nproc > 1:
pool = multiprocessing.Pool(self.nproc)
partial_run_molecule = functools.partial(self.run_molecule, force_field=system.force_field,
allow_name=self.allow_name,
allow_dist=self.allow_dist,
fudge=self.fudge)
system.molecules = pool.map(partial_run_molecule, system.molecules)
else:
mols = []
for molecule in system.molecules:
mols.append(self.run_molecule(molecule))
system.molecules = mols

def run_molecule(self, molecule):
"""
Expand Down