| 1 | import multiprocessing as mp
|
|---|
| 2 | from time import sleep
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 | def do_sim():
|
|---|
| 6 | from simtk.openmm import app
|
|---|
| 7 | from simtk import openmm
|
|---|
| 8 | from simtk import unit
|
|---|
| 9 | platform = openmm.Platform.getPlatformByName('OpenCL')
|
|---|
| 10 | pdb = app.PDBFile('input.pdb')
|
|---|
| 11 | forcefield = app.ForceField('amber99sb.xml', 'amber99_obc.xml')
|
|---|
| 12 | system = forcefield.createSystem(pdb.topology, nonbondedMethod=app.CutoffNonPeriodic, nonbondedCutoff=1.0*unit.nanometer, constraints=app.HBonds)
|
|---|
| 13 | integrator = openmm.LangevinIntegrator(300*unit.kelvin, 1/unit.picosecond, 0.002*unit.picoseconds)
|
|---|
| 14 | context = openmm.Context(system, integrator, platform)
|
|---|
| 15 | context.setPositions(pdb.positions)
|
|---|
| 16 | context.setVelocitiesToTemperature(300*unit.kelvin)
|
|---|
| 17 | context.getIntegrator().step(100)
|
|---|
| 18 |
|
|---|
| 19 | #do_sim()
|
|---|
| 20 | #print('done')
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 | def sim_thread(queue):
|
|---|
| 25 | do_sim()
|
|---|
| 26 | queue.put('Finished')
|
|---|
| 27 |
|
|---|
| 28 | global error
|
|---|
| 29 | error = False
|
|---|
| 30 |
|
|---|
| 31 | def error_cb(e):
|
|---|
| 32 | global error
|
|---|
| 33 | print(e)
|
|---|
| 34 | error = True
|
|---|
| 35 |
|
|---|
| 36 | manager = mp.Manager()
|
|---|
| 37 | out_q = manager.Queue()
|
|---|
| 38 |
|
|---|
| 39 | error = None
|
|---|
| 40 |
|
|---|
| 41 | p = mp.Pool(processes = 1)
|
|---|
| 42 | p.apply_async(sim_thread, args = (out_q, ), error_callback = error_cb)
|
|---|
| 43 | msg_count = 0
|
|---|
| 44 | while msg_count < 1:
|
|---|
| 45 | if error:
|
|---|
| 46 | break
|
|---|
| 47 | if not out_q.empty():
|
|---|
| 48 | msg = out_q.get()
|
|---|
| 49 | if msg == 'Fail!':
|
|---|
| 50 | error = msg
|
|---|
| 51 | break
|
|---|
| 52 | print(msg)
|
|---|
| 53 | msg_count += 1
|
|---|
| 54 | sleep(1e-1)
|
|---|