Skip to content
Snippets Groups Projects
Commit 1909c02c authored by James Graham's avatar James Graham
Browse files

Started parallel mapping issue #10

parent 1621caa9
Branches
Tags
No related merge requests found
...@@ -7,6 +7,8 @@ Each list corresponds to a single molecule. ...@@ -7,6 +7,8 @@ Each list corresponds to a single molecule.
import numpy as np import numpy as np
import warnings import warnings
import itertools
import multiprocessing
from .frame import Atom, Residue, Frame from .frame import Atom, Residue, Frame
from .parsers.cfg import CFG from .parsers.cfg import CFG
...@@ -83,6 +85,8 @@ class Mapping: ...@@ -83,6 +85,8 @@ class Mapping:
self._map_center = options.map_center self._map_center = options.map_center
# self._pool = multiprocessing.Pool(processes=4)
with CFG(filename) as cfg: with CFG(filename) as cfg:
self._manual_charges = {} self._manual_charges = {}
for mol in cfg: for mol in cfg:
...@@ -179,7 +183,13 @@ class Mapping: ...@@ -179,7 +183,13 @@ class Mapping:
cgframe.number = frame.number cgframe.number = frame.number
cgframe.box = frame.box cgframe.box = frame.box
for aares, cgres in zip(aa_residues, cgframe): with multiprocessing.Pool(processes=1) as pool:
cgframe.residues = list(pool.map(self.map_one, zip(aa_residues, cgframe, itertools.repeat(cgframe.box))))
return cgframe
def map_one(self, tup):
aares, cgres, box = tup
molmap = self._mappings[aares.name] molmap = self._mappings[aares.name]
for i, (bead, bmap) in enumerate(zip(cgres, molmap)): for i, (bead, bmap) in enumerate(zip(cgres, molmap)):
...@@ -187,7 +197,7 @@ class Mapping: ...@@ -187,7 +197,7 @@ class Mapping:
coords = np.array([aares[atom].coords for atom in bmap], dtype=np.float32) coords = np.array([aares[atom].coords for atom in bmap], dtype=np.float32)
if self._map_center == "geom": if self._map_center == "geom":
bead.coords = calc_coords(ref_coords, coords, cgframe.box) bead.coords = calc_coords(ref_coords, coords, box)
else: else:
try: try:
weights = bmap.weights[self._map_center] weights = bmap.weights[self._map_center]
...@@ -197,10 +207,9 @@ class Mapping: ...@@ -197,10 +207,9 @@ class Mapping:
else: else:
e.args = ("Error with mapping type '{0}', unknown mapping type.".format(e.args[0]),) e.args = ("Error with mapping type '{0}', unknown mapping type.".format(e.args[0]),)
raise raise
bead.coords = calc_coords_weight(ref_coords, coords, cgframe.box, weights) bead.coords = calc_coords_weight(ref_coords, coords, box, weights)
return cgframe
return cgres
@numba.jit @numba.jit
def calc_coords_weight(ref_coords, coords, box, weights): def calc_coords_weight(ref_coords, coords, box, weights):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment