1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
# Example of multiprocessing: travers subdirectories and process asynchronously
# coordinate files using 4 processes in parallel.
import multiprocessing
import sys
import gemmi
def f(path):
st = gemmi.read_structure(path)
weight = st[0].calculate_mass()
return (st.name, weight)
def main(top_dir):
with multiprocessing.Pool(processes=4) as pool:
it = pool.imap_unordered(f, gemmi.CoorFileWalk(top_dir))
for (name, weight) in it:
print(f'{name} {weight / 1000:.1f} kDa')
if __name__ == '__main__':
main(sys.argv[1])
|