Beispiel #1
0
def main():
    parser = argparse.ArgumentParser(
        description='Prepare system for dynamic undocking')
    parser.add_argument('-p', '--protein', help='Apoprotein in PDB format')
    parser.add_argument('-l', '--ligand', help='Ligand in mol format')
    # parser.add_argument('-o', '--output', help="PDB output")
    parser.add_argument('-c', '--chunk', help='Chunked protein')
    parser.add_argument('-i',
                        '--interaction',
                        help='Protein atom to use for ligand interaction.')
    parser.add_argument('-s', '--seed', type=int, help='Random seed.')
    parser.add_argument(
        '--gpu-id',
        type=int,
        help='GPU ID (optional); if not specified, runs on CPU only.')
    parser.add_argument('--force-constant-eq',
                        type=float,
                        default=1.0,
                        help='Force constant for equilibration.')

    args = parser.parse_args()
    # Parameterize the ligand

    prepare_system(args.ligand, args.chunk)
    # Now find the interaction and save to a file
    results = find_interaction(args.interaction, args.protein)
    print(results)  # what happens to these?
    with open('complex_system.pickle', 'rb') as f:
        p = pickle.load(f) + results
    with open('complex_system.pickle', 'wb') as f:
        pickle.dump(p, f, protocol=pickle.HIGHEST_PROTOCOL)

    #     pickle.dump(l, 'complex_system.pickle')
    # Now do the equlibration
    do_equlibrate(force_constant_equilibrate=args.force_constant_eq,
                  gpu_id=args.gpu_id)
    if not check_if_equlibrated("density.csv", 1):
        raise EquilibrationError("System is not equilibrated.")
Beispiel #2
0
def run_steered_md(
    temperature,
    checkpoint_in_file,
    csv_out_file,
    dat_out_file,
    pdb_out_file,
    traj_out_file,
    startdist,
    spring_constant=50,
    force_constant_chunk=0.1,
    init_velocity=0.00001,
    gpu_id=0,
):
    if os.path.isfile(pdb_out_file):
        return
    spring_k = spring_constant * u.kilocalorie / (u.mole * u.angstrom *
                                                  u.angstrom)
    dist_in = startdist * u.angstrom  # in angstrom
    dist_fin = (startdist + 2.5) * u.angstrom  # in angstrom
    steps_per_move = 200
    velocity = init_velocity * u.angstrom
    # Platform definition
    platform = mm.Platform_getPlatformByName("OpenCL")
    platformProperties = {}
    platformProperties["OpenCLPrecision"] = "mixed"
    platformProperties["OpenCLDeviceIndex"] = gpu_id
    print("loading pickle")
    pickle_in = open("complex_system.pickle", "rb")
    combined_pmd = pickle.load(pickle_in)[0]
    print(combined_pmd)
    pickle_in.close()
    keyInteraction = cal_ints.find_interaction()
    print(keyInteraction)
    # Get indexes of heavy atoms in chunk
    Chunk_Heavy_Atoms = duck_stuff.getHeavyAtomsInSystem(combined_pmd)
    # Setting System
    system = combined_pmd.createSystem(
        nonbondedMethod=app.PME,
        nonbondedCutoff=9 * u.angstrom,
        constraints=app.HBonds,
        hydrogenMass=None,
    )
    # Apply force on all havy atoms of chunk
    duck_stuff.applyHarmonicPositionalRestraints(system, force_constant_chunk,
                                                 combined_pmd.positions,
                                                 Chunk_Heavy_Atoms)
    # Integrator
    integrator = mm.LangevinIntegrator(temperature, 4 / u.picosecond,
                                       0.002 * u.picosecond)
    # Setting Simulation object and loading the checkpoint
    simulation = app.Simulation(combined_pmd.topology, system, integrator,
                                platform, platformProperties)
    simulation.loadCheckpoint(checkpoint_in_file)
    # SMD force definition
    pullforce = mm.CustomExternalForce("k_sp*0.5*(R-R0)^2; \
                                       R = periodicdistance(x, y, z, x0, y0, z0);"
                                       )
    pullforce.addPerParticleParameter("k_sp")
    pullforce.addGlobalParameter("x0", 0.0 * u.nanometer)
    pullforce.addGlobalParameter("y0", 0.0 * u.nanometer)
    pullforce.addGlobalParameter("z0", 0.0 * u.nanometer)
    pullforce.addGlobalParameter("R0", 0.0 * u.nanometer)
    pullforce.addParticle(keyInteraction[1], [spring_k])
    system.addForce(pullforce)
    # Redefine integrator and simulation, and load checkpoint with new-updated system
    integrator = mm.LangevinIntegrator(temperature, 4 / u.picosecond,
                                       0.002 * u.picosecond)
    simulation = app.Simulation(combined_pmd.topology, system, integrator,
                                platform, platformProperties)
    simulation.loadCheckpoint(checkpoint_in_file)
    # Initializing energy
    work_val_old = u.Quantity(value=0, unit=u.kilocalorie / u.mole)
    # Number of big steps and pull distance
    steps = int(round((dist_fin - dist_in) / velocity) / steps_per_move)
    pull_distance = velocity * steps_per_move
    # Reporters and duck.dat file
    simulation.reporters.append(
        app.StateDataReporter(
            csv_out_file,
            steps_per_move,
            step=True,
            time=True,
            totalEnergy=True,
            kineticEnergy=True,
            potentialEnergy=True,
            temperature=True,
            density=True,
            progress=True,
            totalSteps=steps_per_move * steps,
            speed=True,
        ))
    simulation.reporters.append(app.DCDReporter(traj_out_file, 100000))
    f = open(dat_out_file, "w")
    # Production in N steps with the update every 200 steps (2 pm)
    for i in range(steps):
        # Get current state tu update the system
        state = simulation.context.getState(getPositions=True)
        pos_keyInt = state.getPositions()
        keyInteraction_pos = [
            pos_keyInt[keyInteraction[0]],
            pos_keyInt[keyInteraction[1]],
        ]
        # Get radius of starting point and end point
        R_val = dist_in + float(i + 1) * pull_distance
        R_val_start = dist_in + float(i) * pull_distance
        # Get distance of main interaction
        keyInteraction_dist = np.linalg.norm(keyInteraction_pos[0] -
                                             keyInteraction_pos[1])
        print(keyInteraction_dist)
        # Updated system
        simulation.context.setParameter("x0", keyInteraction_pos[0][0])
        simulation.context.setParameter("y0", keyInteraction_pos[0][1])
        simulation.context.setParameter("z0", keyInteraction_pos[0][2])
        simulation.context.setParameter("R0", R_val)
        # Calculate force F = -k * x
        force_val = -spring_k * (keyInteraction_dist - R_val)
        # Make step
        simulation.step(steps_per_move)
        # Calculate work for difference in potential energy in tranzition
        # W = EK_end - EK_start
        # EK = 0.5 * k * x^2
        spr_energy_end = 0.5 * spring_k * (keyInteraction_dist - R_val)**2
        spr_energy_start = 0.5 * spring_k * (keyInteraction_dist -
                                             R_val_start)**2
        work_val = work_val_old + spr_energy_end - spr_energy_start
        work_val_old = work_val
        # Write duck.dat file
        f.write(
            str(i) + " " + str(R_val) + " " + str(keyInteraction_dist) + " " +
            str(force_val) + " " + str(work_val) + "\n")
    f.close()
    # Save state in PDB file
    positions = simulation.context.getState(getPositions=True).getPositions()
    app.PDBFile.writeFile(simulation.topology, positions,
                          open(pdb_out_file, "w"))
def run_simulation(
    prot_file,
    mol_file,
    prot_code,
    prot_int,
    cutoff,
    init_velocity,
    num_smd_cycles,
    gpu_id,
    md_len,
    params,
):
    if not os.path.isfile("equil.chk"):
        # A couple of file name
        orig_file = prot_file
        chunk_protein = "protein_out.pdb"
        chunk_protein_prot = "protein_out_prot.pdb"
        # Do the removal of buffer mols and alt locs
        if params.get("remove_buffers", True):
            prot_file = remove_prot_buffers_alt_locs(prot_file)
        # Do the chunking and the protonation
        if params.get("prep_chunk", True):
            # Chunk
            chunk_with_amber(mol_file, prot_file, prot_int, chunk_protein,
                             cutoff, orig_file)
            # Protontate
            disulfides = find_disulfides(chunk_protein)
            do_tleap(chunk_protein, chunk_protein_prot, disulfides)
        else:
            chunk_protein_prot = prot_file
        # Paramaterize the ligand
        mol2_file = params.get("mol2_file_prepped", None)
        if not mol2_file:
            results = prep_lig(mol_file, prot_code)
            mol2_file = results[0]
        prepare_system(mol2_file, chunk_protein_prot)
        # Now find the interaction and save to a file
        results = find_interaction(prot_int, orig_file)
        startdist = params.get("distance", results[2])
        # Now do the equlibration
        do_equlibrate(gpu_id=gpu_id)
    else:
        # Now find the interaction and save to a file
        results = find_interaction(prot_int, prot_file)
        startdist = params.get("distance", results[2])
    # Open the file and check that the potential is stable and negative
    if not check_if_equlibrated("density.csv", 1):
        print("SYSTEM NOT EQUILIBRATED")
        sys.exit()
    if params.get("just_equilib", False):
        print("SYSTEM FENISHED EQULIBRATING")
        return
    # Now do the MD
    for i in range(num_smd_cycles):
        if i == 0:
            md_start = "equil.chk"
        else:
            md_start = "md_" + str(i - 1) + ".chk"
        log_file = "md_" + str(i) + ".csv"
        perform_md(
            md_start,
            "md_" + str(i) + ".chk",
            log_file,
            "md_" + str(i) + ".pdb",
            md_len=md_len,
            gpu_id=gpu_id,
        )
        # Open the file and check that the potential is stable and negative
        if not check_if_equlibrated(log_file, 3):
            print("SYSTEM NOT EQUILIBRATED")
            sys.exit()
        # Now find the interaction and save to a file
        run_steered_md(
            300,
            "md_" + str(i) + ".chk",
            "smd_" + str(i) + "_300.csv",
            "smd_" + str(i) + "_300.dat",
            "smd_" + str(i) + "_300.pdb",
            "smd_" + str(i) + "_300.dcd",
            startdist,
            init_velocity=init_velocity,
            gpu_id=gpu_id,
        )
        run_steered_md(
            325,
            "md_" + str(i) + ".chk",
            "smd_" + str(i) + "_325.csv",
            "smd_" + str(i) + "_325.dat",
            "smd_" + str(i) + "_325.pdb",
            "smd_" + str(i) + "_325.dcd",
            startdist,
            init_velocity=init_velocity,
            gpu_id=gpu_id,
        )
Beispiel #4
0
def perform_md(
    checkpoint_in_file,
    checkpoint_out_file,
    csv_out_file,
    pdb_out_file,
    force_constant_ligand=1.0,
    md_len=1.0,
    force_constant_chunk=0.1,
    gpu_id=0,
):
    if os.path.isfile(checkpoint_out_file):
        return
    print("loading pickle")
    pickle_in = open("complex_system.pickle", "rb")
    combined_pmd = pickle.load(pickle_in)[0]
    print(dir(combined_pmd))
    key_interaction = cal_ints.find_interaction()
    pickle_in.close()
    MD_len = md_len * u.nanosecond
    sim_steps = round(MD_len / (0.002 * u.picosecond))
    # Platform definition
    platform = mm.Platform_getPlatformByName("CUDA")
    platformProperties = {}
    platformProperties["CudaPrecision"] = "double"
    platformProperties["CudaDeviceIndex"] = gpu_id
    platformProperties["DeterministicForces"] = 'true'
    # Get indexes of heavy atoms in chunk
    Chunk_Heavy_Atoms = duck_stuff.getHeavyAtomsInSystem(combined_pmd)
    # Setting System
    system = combined_pmd.createSystem(
        nonbondedMethod=app.PME,
        nonbondedCutoff=9 * u.angstrom,
        constraints=app.HBonds,
        hydrogenMass=None,
    )
    # Apply force on all havy atoms of chunk and apply restraint for the ligand-chunk distance
    duck_stuff.applyHarmonicPositionalRestraints(system, force_constant_chunk,
                                                 combined_pmd.positions,
                                                 Chunk_Heavy_Atoms)
    duck_stuff.applyLigandChunkRestraint(
        system,
        force_constant_ligand,
        10.0,
        2 * u.angstrom,
        3 * u.angstrom,
        4 * u.angstrom,
        key_interaction,
    )
    # Integrator
    integrator = mm.LangevinIntegrator(300 * u.kelvin, 4 / u.picosecond,
                                       0.002 * u.picosecond)
    # Setting Simulation object and loading the checkpoint
    simulation = app.Simulation(combined_pmd.topology, system, integrator,
                                platform, platformProperties)
    simulation.loadCheckpoint(checkpoint_in_file)
    # Simulation reporters
    simulation.reporters.append(
        app.StateDataReporter(
            csv_out_file,
            2000,
            step=True,
            time=True,
            totalEnergy=True,
            kineticEnergy=True,
            potentialEnergy=True,
            temperature=True,
            density=True,
            progress=True,
            totalSteps=sim_steps,
            speed=True,
        ))
    simulation.reporters.append(app.DCDReporter("md.dcd", 100000))
    # Production
    simulation.step(sim_steps)
    # Save state in checkpoint file and save coordinates in PDB file
    state = simulation.context.getState(getPositions=True, getVelocities=True)
    positions = state.getPositions()
    app.PDBFile.writeFile(simulation.topology, positions,
                          open(pdb_out_file, "w"))
    simulation.saveCheckpoint(checkpoint_out_file)
Beispiel #5
0
from duck.utils.get_from_fragalysis import get_from_prot_code
from duck.utils.cal_ints import find_interaction
from duck.steps.normal_md import perform_md
from duck.steps.steered_md import run_steered_md
# Define these
prot_code = "MURD-x0374"
prot_int = "A_LYS_311_N"
# Cutoff for the sphere
# Now it does the magic
results = get_from_prot_code(prot_code)
prot_file = results[0]
# Now find the interaction and save to a file

results = find_interaction(prot_int, prot_file)
startdist = results[2]
for i in range(20):
    if i == 0:
        md_start = "equil.chk"
    else:
        md_start = "md_" + str(i - 1) + ".chk"
    perform_md(md_start,
               "md_" + str(i) + ".chk",
               "md_" + str(i) + ".csv",
               "md_" + str(i) + ".pdb",
               md_len=0.5)
    # Now find the interaction and save to a file
    run_steered_md(300, "md_" + str(i) + ".chk", "smd_" + str(i) + "_300.csv",
                   "smd_" + str(i) + "_300.dat", "smd_" + str(i) + "_300.pdb",
                   "smd_" + str(i) + "_300.dcd", startdist)
    run_steered_md(325, "md_" + str(i) + ".chk", "smd_" + str(i) + "_325.csv",
                   "smd_" + str(i) + "_325.dat", "smd_" + str(i) + "_325.pdb",
Beispiel #6
0
def do_equlibrate(force_constant_equilibrate=1.0, gpu_id=0):
    # Find the interations
    keyInteraction = cal_ints.find_interaction()
    # Platform definition
    platform = mm.Platform_getPlatformByName("OpenCL")
    platformProperties = {}
    platformProperties['OpenCLPrecision'] = 'mixed'
    platformProperties["OpenCLDeviceIndex"] = gpu_id
    print("loading pickle")
    pickle_in = open('complex_system.pickle', 'rb')
    combined_pmd = pickle.load(pickle_in)[0]
    combined_pmd.symmetry = None
    pickle_in.close()
    ##################
    ##################
    #  Minimisation  #
    ##################
    ##################
    print('Minimising...')
    # Define system
    system = combined_pmd.createSystem(nonbondedMethod=app.PME,
                                       nonbondedCutoff=9 * u.angstrom)
    # Get indexes of heavy atoms in chunk
    Chunk_Heavy_Atoms = duck_stuff.getHeavyAtomsInSystem(combined_pmd)
    # Apply force on all havy atoms of chunk
    duck_stuff.applyHarmonicPositionalRestraints(system,
                                                 force_constant_equilibrate,
                                                 combined_pmd.positions,
                                                 Chunk_Heavy_Atoms)
    # Integrator
    integrator = mm.VerletIntegrator(1 * u.femtosecond)
    # Define Simulation
    simulation = app.Simulation(combined_pmd.topology, system, integrator,
                                platform, platformProperties)
    simulation.context.setPositions(combined_pmd.positions)
    print(simulation.context.getPlatform().getName())
    for key in simulation.context.getPlatform().getPropertyNames():
        print(
            key,
            simulation.context.getPlatform().getPropertyValue(
                simulation.context, key))
    # Minimizing energy
    simulation.minimizeEnergy(maxIterations=1000)
    # Saving minimised positions
    positions = simulation.context.getState(getPositions=True).getPositions()
    app.PDBFile.writeFile(simulation.topology, positions,
                          open('minimisation.pdb', 'w'))
    ##########################
    ##########################
    # Equlibration - heating #
    ##########################
    ##########################
    #new minimised positions, however using old restraints
    # Define new system
    system = combined_pmd.createSystem(nonbondedMethod=app.PME,
                                       nonbondedCutoff=9 * u.angstrom,
                                       constraints=app.HBonds,
                                       hydrogenMass=None)
    # Apply force on all havy atoms of chunk and apply restraint for the ligand-chunk distance
    duck_stuff.applyHarmonicPositionalRestraints(system,
                                                 force_constant_equilibrate,
                                                 combined_pmd.positions,
                                                 Chunk_Heavy_Atoms)
    duck_stuff.applyLigandChunkRestraint(system, force_constant_equilibrate,
                                         10.0, 2 * u.angstrom, 3 * u.angstrom,
                                         4 * u.angstrom, keyInteraction)
    # Intergator
    integrator = mm.LangevinIntegrator(300 * u.kelvin, 4 / u.picosecond,
                                       0.002 * u.picosecond)
    # Define Simulation
    simulation = app.Simulation(combined_pmd.topology, system, integrator,
                                platform, platformProperties)
    simulation.context.setPositions(
        positions)  #changing coordintes to minimized
    # Reporters
    simulation.reporters.append(
        app.StateDataReporter("heating.csv",
                              1000,
                              time=True,
                              potentialEnergy=True,
                              temperature=True,
                              density=True,
                              remainingTime=True,
                              speed=True,
                              totalSteps=50000))
    simulation.reporters.append(app.DCDReporter("heating.dcd", 1000))
    # Heating the system
    print("Heating ... ")
    simulation.step(50000)  # 0.01 ns
    # Save the positions and velocities
    positions = simulation.context.getState(getPositions=True).getPositions()
    velocities = simulation.context.getState(
        getVelocities=True).getVelocities()
    app.PDBFile.writeFile(simulation.topology, positions,
                          open('heating_final.pdb', 'w'))
    #clear reporters
    simulation.reporters = []
    ##########################
    ##########################
    # Equlibration - density #
    ##########################
    ##########################
    simulation = duck_stuff.setUpNPTEquilibration(system, combined_pmd,
                                                  platform, platformProperties,
                                                  positions, velocities)
    # Reporters
    simulation.reporters.append(
        app.StateDataReporter("density.csv",
                              1000,
                              time=True,
                              potentialEnergy=True,
                              temperature=True,
                              density=True,
                              remainingTime=True,
                              speed=True,
                              totalSteps=50000))
    # Correcting the density
    print("Correcting density")
    simulation.step(50000)  # 0.01 ns
    # Save the positions and velocities
    positions = simulation.context.getState(getPositions=True).getPositions()
    velocities = simulation.context.getState(
        getVelocities=True).getVelocities()
    app.PDBFile.writeFile(simulation.topology, positions,
                          open('density_final.pdb', 'w'))
    #saving simulation stage
    checkpoint = 'equil.chk'
    simulation.saveCheckpoint(checkpoint)
    return [checkpoint]