Beispiel #1
0
def run_md(script, coordinates, topology):
    """
    Run an MD job.
    
    Args:
        script (str): The script of control parameters.
        coordinates (Amber .crd format): starting coordinates.
        topology (Amber .prmtop format): topology and forcefield information.
        
    Returns:
        final_coordinates (Amber .ncrst format)
        trajectory (Amber .nc format)
        log_file (text file)
    """
    from xbowflow import xflowlib
    import os

    with open('script_file', 'w') as f:
        f.write(script)
    script_file = xflowlib.load('script_file')
    os.remove('script_file')
    md = xflowlib.SubprocessKernel(
        'pmemd -i x.in -c x.crd -p x.prmtop -x x.nc -r x.ncrst -o x.log')
    md.set_inputs(['x.in', 'x.crd', 'x.prmtop'])
    md.set_outputs(['x.ncrst', 'x.nc', 'x.log'])
    return md.run(script_file, coordinates, topology)
Beispiel #2
0
def run_leap(parameters, script, structure):
    """
    Run the Amber leap command on the given structure, using the given script.
    
    Args:
        parameters (str or list of strs): Names of parameter files.
        script (str): The leap input script.
        structure (object): SOmething with a .save() method that can produce a pdb format file.
        
    Returns:
        topology: Amber topology
        coordinates: Amber coordinates
        
    """
    from xbowflow import xflowlib
    import os

    if isinstance(parameters, str):
        params = [parameters]
    else:
        params = parameters
    with open('leap.in', 'w') as f:
        for p in params:
            f.write('source {} \n'.format(p))
        f.write('x = loadpdb x.pdb\n')
        f.write(script)
        f.write('saveamberparm x x.prmtop x.rst7\nquit\n')
    leapin = xflowlib.load('leap.in')
    os.remove('leap.in')
    leap = xflowlib.SubprocessKernel('tleap -f leap.in')
    leap.set_inputs(['leap.in', 'x.pdb'])
    leap.set_outputs(['x.prmtop', 'x.rst7'])
    topology, coordinates = leap.run(leapin, structure)
    print(leap.STDOUT)
    return topology, coordinates
Beispiel #3
0
def params(mol2file):

    from xbowflow import xflowlib
    mol2 = xflowlib.load(mol2file)

    antechamber = xflowlib.SubprocessKernel(
        'amber-shell antechamber -i chimeraOut.mol2 -fi mol2 -at gaff -an y -du y -o antechOut.prepc -fo prepc -c gas'
    )
    antechamber.set_inputs(['chimeraOut.mol2'])
    antechamber.set_outputs(['antechOut.prepc'])
    prepfile = antechamber.run(mol2)
    return prepfile
Beispiel #4
0
def multirun(client, args):
    # Create and configure kernels:
    cmd1 = 'gmx grompp -f x.mdp -c x.gro -p x.top -o x.tpr'
    grompp = xflowlib.SubprocessKernel(cmd1)
    grompp.set_inputs(['x.mdp', 'x.gro', 'x.top'])
    grompp.set_outputs(['x.tpr'])

    cmd2 = 'gmx mdrun -s x.tpr -o x.trr -x x.xtc -c x.gro -e x.edr -g x.log'
    mdrun = xflowlib.SubprocessKernel(cmd2)
    mdrun.set_inputs(['x.tpr'])
    mdrun.set_outputs(['x.trr', 'x.xtc', 'x.gro', 'x.edr', 'x.log'])

    # Upload data
    startcrds = client.upload(xflowlib.load(args['startcrds']))
    mdpfile = client.upload(xflowlib.load(args['mdpfile']))
    topfile = client.upload(xflowlib.load(args['topfile']))

    # Run kernels
    mdpfiles = [mdpfile] * len(args['repdirs'])
    tprfiles = client.map(grompp, mdpfiles, startcrds, topfile)
    trrfiles, xtcfiles, grofiles, edrfiles, logfiles = client.map(
        mdrun, tprfiles)
    deffnm = args['deffnm']
    # Save final files
    for i, d, in enumerate(args['repdirs']):
        if not os.path.exists(d):
            os.mkdir(d)
        if trrfiles[i].result() is not None:
            trrfiles[i].result().save('{}/{}.trr'.format(d, deffnm))
        if xtcfiles[i].result() is not None:
            xtcfiles[i].result().save('{}/{}.xtc'.format(d, deffnm))
        if grofiles[i].result() is not None:
            grofiles[i].result().save('{}/{}.gro'.format(d, deffnm))
        if edrfiles[i].result() is not None:
            edrfiles[i].result().save('{}/{}.edr'.format(d, deffnm))
        if logfiles[i].result() is not None:
            logfiles[i].result().save('{}/{}.log'.format(d, deffnm))
Beispiel #5
0
 def test_filehandle_methods_for_temp(self):
     xflowlib.set_filehandler('tmp')
     self.assertEqual(xflowlib.filehandler_type, 'tmp')
     self.assertEqual(xflowlib.filehandler, filehandling.TempFileHandle)
     fh = xflowlib.load('data/test.txt')
     self.assertIsInstance(fh, filehandling.FileHandle)
     fh.save('tempfile.txt')
     self.assertTrue(os.path.exists('tempfile.txt'))
     with open('data/test.txt', 'rb') as f1:
         d1 = f1.read()
     with open('tempfile.txt', 'rb') as f2:
         d2 = f2.read()
     self.assertEqual(d1, d2)
     os.remove('tempfile.txt')
     self.assertFalse(os.path.exists('tempfile.txt'))
     tmpname = fh.as_file()
     self.assertTrue(os.path.exists(tmpname))
Beispiel #6
0
def equilibration(client, args):
    # Create and configure MD kernels:
    cmd = '{mdexe} -O -i md.in -o md.out -c md.crd -p md.prmtop -r md.rst -ref ref.rst -x md.nc'.format(
        **args)
    mdrun1 = xflowlib.SubprocessKernel(cmd)
    mdrun1.set_inputs(['md.crd', 'ref.rst'])
    mdrun1.set_outputs(['md.rst', 'md.nc'])
    mdrun1.set_constant('md.prmtop', args['prmtop'])
    mdrun1.set_constant('md.in', args['mdin1'])

    mdrun2 = mdrun1.copy()
    mdrun2.set_constant('md.in', args['mdin2'])

    mdrun3 = mdrun1.copy()
    mdrun3.set_constant('md.in', args['mdin3'])

    startcrds = client.upload(xflowlib.load(args['startcrds']))

    restart, trajfile = client.submit(mdrun1, startcrds, startcrds)
    restart, trajfile = client.submit(mdrun2, restart, startcrds)
    restart, trajfile = client.submit(mdrun3, restart, startcrds)

    trajfile.result().save(args['outtraj'])
    restart.result().save(args['outcrds'])
Beispiel #7
0
from xbowflow import xflowlib
from xbowflow.clients import XflowClient
from extasycoco.coco import complement


def makemdt(crdfile, topfile):
    '''Make an MDTraj trajectory object from a coordinates file'''
    result = mdt.load(crdfile.as_file(), top=topfile.as_file())
    return result


if __name__ == '__main__':

    mc = XflowClient()

    inpcrd = xflowlib.load('csaw.rst7')
    mdin1 = xflowlib.load('tmd_1.in')
    mdin2 = xflowlib.load('tmd_2.in')
    mdin3 = xflowlib.load('production_md.in')
    prmtop = xflowlib.load('csaw.prmtop')

    md1 = xflowlib.SubprocessKernel(
        'pmemd.cuda -O -i x.mdin -c x.rst7 -p x.prmtop -r out.rst7 -ref ref.rst7 -o x.mdout'
    )
    md1.set_inputs(['x.mdin', 'x.rst7', 'ref.rst7'])
    md1.set_outputs(['out.rst7', 'x.mdout'])
    md1.set_constant('x.prmtop', prmtop)

    md2 = xflowlib.SubprocessKernel(
        'pmemd.cuda -O -i x.mdin -c x.rst7 -p x.prmtop -x out.nc -o x.mdout')
    md2.set_inputs(['x.mdin', 'x.rst7'])
Beispiel #8
0
# Now we start a **Crossflow** client. The client is how we send individual jobs
# out to the worker nodes.
print('Starting a Crossflow client...')
client = XflowClient()

# On the command line we pass data to and from programs by specifying filenames,
# But to run the same job as a function we need to pass the actual data itself,
# So we upload the input data from each input file:
print('Uploading input data...')
startcrd_name = 'bpti.gro'
targetcrd_name = 'bpti-150000.gro'
mdpfile_name = 'mdrun.mdp'
topfile_name = 'bpti.top'

startcrd = client.upload(xflowlib.load(startcrd_name))
mdp = client.upload(xflowlib.load(mdpfile_name))
top = client.upload(xflowlib.load(topfile_name))

n_cycles = 20
n_reps = 12
smallest_rmsd = 10000.0
# We want to run four jobs in parallel, so we need to make four copies of one
# of the files that will be input to grompp - we choose the mdp file:
mdps = [mdp] * n_reps

for cycle in range(n_cycles):
    # Now we run the grompp and mdrun jobs via the client. The "map" command sends
    # each replicate of the job to a different worker (if there are enough of them)
    print('Running the grompp kernel for {} replicates...'.format(n_reps))
    tprs = client.map(grompp, mdps, startcrd, top)
Beispiel #9
0
mdrun.set_outputs(['x.xtc', 'x.gro', 'x.log'])

# Now we start a **Crossflow** client. The client is how we send individual jobs
# out to the worker nodes.
print('Starting a Crossflow client...')
client = XflowClient()

# On the command line we pass data to and from programs by specifying filenames,
# But to run the same job as a function we need to pass the actual data itself,
# So we upload the input data from each input file:
print('Uploading input data...')
startcrds = 'bpti.gro'
mdpfile = 'mdrun.mdp'
topfile = 'bpti.top'

startcrd_data = client.upload(xflowlib.load(startcrds))
mdp_data = client.upload(xflowlib.load(mdpfile))
top_data = client.upload(xflowlib.load(topfile))

# We want to run four jobs in parallel, so we need to make four copies of one
# of the files that will be input to grompp:
n_reps = 4
mdp_datas = [mdp_data] * n_reps

# Now we run the grompp and mdrun jobs via the client. The "map" command sends
# each replicate of the job to a different worker (if there are enough of them)
print('Running the grompp kernel for four replicates...')
tpr_datas = client.map(grompp, mdp_datas, startcrd_data, top_data)
print('Running the mdrun kernel for four replicates...')
xtc_datas, gro_datas, log_datas = client.map(mdrun, tpr_datas)