def build_cgmodel(rosetta_scoring):
    # Set values for the parameters in our coarse grained model:
    polymer_length = 2
    backbone_lengths = [1]
    sidechain_lengths = [1]
    sidechain_positions = [0]
    include_bond_forces = False  # NOTE: By default bonds are constrained to their equilibrium lengths, even when this variable is set to False, unless 'constrain_bonds'=False
    constrain_bonds = True
    include_bond_angle_forces = False
    include_nonbonded_forces = True
    include_torsion_forces = False

    # Particle properties
    mass = 100.0 * unit.amu
    masses = {'backbone_bead_masses': mass, 'sidechain_bead_masses': mass}
    bond_length = 1.0 * unit.angstrom
    bond_lengths = {
        'bb_bb_bond_length': bond_length,
        'bb_sc_bond_length': bond_length,
        'sc_sc_bond_length': bond_length
    }
    bond_force_constant = 0.0 * unit.kilocalorie_per_mole / unit.nanometer / unit.nanometer
    bond_force_constants = {
        'bb_bb_bond_k': bond_force_constant,
        'bb_sc_bond_k': bond_force_constant,
        'sc_sc_bond_k': bond_force_constant
    }
    r_min = bond_length
    sigma = r_min / (2.0**(1 / 6))
    sigmas = {'bb_sigma': sigma, 'sc_sigma': sigma}
    epsilon = 0.2 * unit.kilocalorie_per_mole
    epsilons = {'bb_eps': epsilon, 'sc_eps': epsilon}
    exclusions = True

    # Get positions from a local PDB file written by PyRosetta, and modified (by hand) to have a geometry where the nonbonded interactions are easy to evaluate
    cgmodel = CGModel(polymer_length=polymer_length,
                      backbone_lengths=backbone_lengths,
                      sidechain_lengths=sidechain_lengths,
                      sidechain_positions=sidechain_positions,
                      masses=masses,
                      sigmas=sigmas,
                      epsilons=epsilons,
                      bond_lengths=bond_lengths,
                      include_nonbonded_forces=include_nonbonded_forces,
                      include_bond_forces=include_bond_forces,
                      include_bond_angle_forces=include_bond_angle_forces,
                      include_torsion_forces=include_torsion_forces,
                      rosetta_scoring=rosetta_scoring,
                      exclusions=exclusions,
                      constrain_bonds=constrain_bonds)
    pyrosetta_sequence = ''.join([
        str('X[' + str(monomer['monomer_name']) + ']')
        for monomer in cgmodel.sequence
    ])
    pose = pyrosetta.pose_from_sequence(pyrosetta_sequence)
    pose.dump_pdb("test_pyrosetta.pdb")
    cgmodel.positions = PDBFile("test_pyrosetta.pdb").getPositions()
    cgmodel.topology = build_topology(cgmodel)
    return (cgmodel, pose)
Пример #2
0
def build_cgmodel(rosetta_scoring):
    # Set values for the parameters in our coarse grained model:
    polymer_length = 2
    backbone_lengths = [1]
    sidechain_lengths = [1]
    sidechain_positions = [0]
    include_bond_forces = False  # NOTE: By default bonds are constrained to their equilibrium lengths, even when this variable is set to False, unless 'constrain_bonds'=False
    constrain_bonds = True
    include_bond_angle_forces = True
    include_nonbonded_forces = True
    include_torsion_forces = True

    # Particle properties
    mass = 100.0 * unit.amu
    masses = {'backbone_bead_masses': mass, 'sidechain_bead_masses': mass}
    bond_length = 1.0 * unit.angstrom
    bond_lengths = {
        'bb_bb_bond_length': bond_length,
        'bb_sc_bond_length': bond_length,
        'sc_sc_bond_length': bond_length
    }
    bond_force_constant = 0.0 * unit.kilocalorie_per_mole / unit.nanometer / unit.nanometer
    bond_force_constants = {
        'bb_bb_bond_k': bond_force_constant,
        'bb_sc_bond_k': bond_force_constant,
        'sc_sc_bond_k': bond_force_constant
    }
    r_min = bond_length
    sigma = r_min / (2.0**(1 / 6))
    sigmas = {'bb_sigma': sigma, 'sc_sigma': sigma}
    epsilon = 10.0 * unit.kilocalorie_per_mole
    epsilons = {'bb_eps': epsilon, 'sc_eps': epsilon}
    exclusions = True

    # Bond angle properties
    bond_angle_force_constant = 2 * unit.kilocalorie_per_mole / unit.radian / unit.radian
    bond_angle_force_constants = {
        'bb_bb_sc_angle_k': bond_angle_force_constant
    }
    equil_bond_angle = 90.0 * (3.141 / 180.0)
    equil_bond_angles = {'bb_bb_sc_angle_0': equil_bond_angle}

    # Torsion properties
    torsion_force_constant = 3 * unit.kilocalorie_per_mole / unit.radian / unit.radian
    torsion_force_constants = {'sc_bb_bb_sc_torsion_k': torsion_force_constant}
    torsion_periodicity = 1
    torsion_periodicities = {'sc_bb_bb_sc_period': torsion_periodicity}
    equil_torsion_angle = 0.0 * (3.141 / 180.0)
    equil_torsion_angles = {'sc_bb_bb_sc_torsion_0': equil_torsion_angle}

    # Get positions from a local PDB file written by PyRosetta, and modified (by hand) to have a geometry where the nonbonded interactions are easy to evaluate
    cgmodel = CGModel(polymer_length=polymer_length,
                      backbone_lengths=backbone_lengths,
                      sidechain_lengths=sidechain_lengths,
                      sidechain_positions=sidechain_positions,
                      masses=masses,
                      sigmas=sigmas,
                      epsilons=epsilons,
                      bond_lengths=bond_lengths,
                      include_nonbonded_forces=include_nonbonded_forces,
                      include_bond_forces=include_bond_forces,
                      include_bond_angle_forces=include_bond_angle_forces,
                      include_torsion_forces=include_torsion_forces,
                      rosetta_scoring=rosetta_scoring,
                      exclusions=exclusions,
                      constrain_bonds=constrain_bonds,
                      equil_torsion_angles=equil_torsion_angles,
                      torsion_force_constants=torsion_force_constants,
                      torsion_periodicities=torsion_periodicities,
                      equil_bond_angles=equil_bond_angles,
                      bond_angle_force_constants=bond_angle_force_constants)
    pyrosetta_sequence = ''.join([
        str('X[' + str(monomer['monomer_name']) + ']')
        for monomer in cgmodel.sequence
    ])
    res_file_list = list(
        set([
            str(str(monomer['monomer_name']) + ".params")
            for monomer in cgmodel.sequence
        ]))
    res_file_list = " ".join(res_file_list)
    assign_mm_atom_properties_with_cgopenmm_cgmodel(cgmodel)
    exit()
    pose = pyrosetta.pose_from_sequence(pyrosetta_sequence)
    for residue_index in range(pose.total_residue()):
        print(pose.residue(residue_index))
    exit()
    pose.dump_pdb("test_pyrosetta.pdb")
    cgmodel.positions = PDBFile("test_pyrosetta.pdb").getPositions()
    cgmodel.topology = build_topology(cgmodel)
    return (cgmodel, pose)
Пример #3
0
                except:
                    os.remove(output_data)
        else:
            replica_energies, replica_positions, replica_states = read_replica_exchange_data(
                system=cgmodel.system,
                topology=cgmodel.topology,
                temperature_list=temperature_list,
                output_data=output_data,
                print_frequency=print_frequency)

        steps_per_stage = round(total_steps / exchange_attempts)

        minimum_energy_structure = get_native_structure(
            replica_positions, replica_energies, temperature_list)

        cgmodel.positions = minimum_energy_structure

        pitch, radius, monomers_per_turn, residual = get_helical_parameters(
            cgmodel)

        pitch_list.append(pitch)
        radius_list.append(radius)
        monomers_per_turn_list.append(monomers_per_turn)
        residual_list.append(residual)

        data = open("helical_data.dat", "a")
        data.write(
            str(round(sigma._value, 3)) + " " + str(round(epsilon._value, 3)) +
            " " + str(round(float(pitch), 3)) + " " +
            str(round(float(radius), 3)) + " " +
            str(round(float(monomers_per_turn), 3)) + " " +
Пример #4
0
run_simulation(cgmodel,output_directory,total_simulation_time,simulation_time_step,1.0*unit.kelvin,20,output_pdb="output.pdb",output_data="output.dat")

model_angle_list = cgmodel.bond_angle_list
angle_list = []
for angle in model_angle_list:
  if all([cgmodel.get_particle_type(i) == "backbone" for i in angle]):
    angle_list.append(angle)

init_pose = False
attempts = 0
max_attempts = 100
while not os.path.exists("native_structure.pdb"):
 try:
  print("reading in a structure")
  cgmodel.positions = PDBFile("init.pdb").getPositions()
  print("minimize the structure")
  cgmodel.positions,energy,simulation = minimize_structure(cgmodel.topology,cgmodel.system,cgmodel.positions,temperature=1.0*unit.kelvin,simulation_time_step=simulation_time_step,output_data="output.dat",output_pdb="output.pdb")
  print("minimization succeeded.")
  if not os.path.exists(output_data):
     print("performing replica exchange simulations")
     replica_energies,replica_positions,replica_states = run_replica_exchange(cgmodel.topology,cgmodel.system,cgmodel.positions,temperature_list=temperature_list,simulation_time_step=simulation_time_step,total_simulation_time=total_simulation_time,print_frequency=print_frequency,output_data=output_data)
     make_replica_pdb_files(cgmodel.topology,replica_positions)
  else:
     print("reading replica exchange simulation data")
     replica_energies,replica_positions,replica_states = read_replica_exchange_data(system=cgmodel.system,topology=cgmodel.topology,temperature_list=temperature_list,output_data=output_data,print_frequency=print_frequency)
  native_structure = get_native_structure(replica_positions,replica_energies,temperature_list)

  cgmodel.positions = get_native_structure(replica_positions,replica_energies,temperature_list)

            str(top_directory) + "/torsions_" +
            str(round(bb_bb_bb_bb_equil_torsion_angle, 2)) + "_" +
            str(round(sc_bb_bb_sc_equil_torsion_angle, 2)) + ".pdb")
        minimum_energy_structures = get_minimum_energy_pose(
            cgmodel.topology,
            replica_energies,
            replica_positions,
            file_name=output_file)

        #if not os.path.exists(output_data):

        p_list = []
        r_list = []
        mpt_list = []
        for structure in minimum_energy_structures:
            cgmodel.positions = structure
            pitch, radius, monomers_per_turn = get_helical_parameters(cgmodel)
            p_list.append(pitch)
            r_list.append(radius)
            mpt_list.append(monomers_per_turn)
        pitch = mean(np.array([float(p) for p in p_list]))
        radius = mean(np.array([float(r) for r in r_list]))
        monomers_per_turn = mean(np.array([float(mpt) for mpt in mpt_list]))

        data = open("helical_data.dat", "a")
        data.write(
            str(round(bb_bb_bb_bb_equil_torsion_angle, 2)) + "_" +
            str(round(sc_bb_bb_sc_equil_torsion_angle, 2)) + " " +
            str(round(float(pitch), 3)) + " " + str(round(float(radius), 3)) +
            " " + str(round(float(monomers_per_turn), 3)) + "\n")
        data.close()
Пример #6
0
if os.path.exists(nonnative_ensemble_directory):
    nonnative_ensemble, nonnative_ensemble_energies = get_ensemble_data(
        cgmodel, nonnative_ensemble_directory)
    if len(nonnative_ensemble) != nonnative_ensemble_size:
        print("ERROR: " + str(len(nonnative_ensemble_energies)) +
              " nonnative poses were found in existing output folders, but " +
              str(nonnative_ensemble_size) + " poses were requested.")
        print(
            "This probably means that the requested ensemble size changed since the script was last run."
        )
        exit()
else:
    os.mkdir(nonnative_ensemble_directory)
    for pose in nonnative_ensemble:
        cgmodel.positions = pose
        write_ensemble_pdb(cgmodel,
                           ensemble_directory=nonnative_ensemble_directory)

if os.path.exists(native_ensemble_directory):
    native_ensemble, native_ensemble_energies = get_ensemble_data(
        cgmodel, native_ensemble_directory)
    if len(native_ensemble_energies) != native_ensemble_size:
        print("ERROR: " + str(len(native_ensemble_energies)) +
              " native poses were found in existing output folders, but " +
              str(native_ensemble_size) + " poses were requested.")
        print(
            "This probably means that the requested ensemble size changed since the script was last run."
        )
        exit()
else:
def build_cgmodel():
    # Set values for the parameters in our coarse grained model:
    polymer_length = 3
    backbone_lengths = [1]
    sidechain_lengths = [1]
    sidechain_positions = [0]
    include_bond_forces = False  # NOTE: Bonds are constrained to their equilibrium lengths, by default, even when this variable is set to False.
    include_bond_angle_forces = False
    include_nonbonded_forces = True
    include_torsion_forces = False
    rosetta_scoring = True

    # Particle properties
    mass = 100.0 * unit.amu
    masses = {'backbone_bead_masses': mass, 'sidechain_bead_masses': mass}
    bond_length = 1.0 * unit.angstrom
    bond_lengths = {
        'bb_bb_bond_length': bond_length,
        'bb_sc_bond_length': bond_length,
        'sc_sc_bond_length': bond_length
    }
    bond_force_constant = 0.0 * unit.kilocalorie_per_mole / unit.nanometer / unit.nanometer
    bond_force_constants = {
        'bb_bb_bond_k': bond_force_constant,
        'bb_sc_bond_k': bond_force_constant,
        'sc_sc_bond_k': bond_force_constant
    }
    r_min = bond_length
    sigma = r_min / (2.0**(1 / 6))
    sigmas = {'bb_bb_sigma': sigma, 'sc_sc_sigma': sigma}
    epsilon = 0.2 * unit.kilocalorie_per_mole
    epsilons = {'bb_bb_eps': epsilon, 'sc_sc_eps': epsilon}
    # Bond angle properties
    bond_angle_force_constant = 2 * unit.kilocalorie_per_mole / unit.radian / unit.radian
    bond_angle_force_constants = {
        'bb_bb_bb_angle_k': bond_angle_force_constant,
        'bb_bb_sc_angle_k': bond_angle_force_constant
    }
    equil_bond_angle = 120.0 * (3.141 / 180.0)
    equil_bond_angles = {
        'bb_bb_bb_angle_0': equil_bond_angle,
        'bb_bb_sc_angle_0': equil_bond_angle
    }
    # Torsion properties
    torsion_force_constant = 3
    torsion_force_constants = {
        'bb_bb_bb_bb_torsion_k': torsion_force_constant,
        'sc_bb_bb_sc_torsion_k': 0.0,
        'bb_bb_bb_sc_torsion_k': 0.0,
        'sc_bb_bb_bb_torsion_k': 0.0
    }
    torsion_periodicity = 3
    torsion_periodicities = {
        'bb_bb_bb_bb_period': torsion_periodicity,
        'sc_bb_bb_sc_period': 0,
        'bb_bb_bb_sc_period': 0,
        'sc_bb_bb_bb_period': 0
    }
    equil_torsion_angle = 0.0 * (3.141 / 180.0)
    equil_torsion_angles = {
        'bb_bb_bb_bb_torsion_0': equil_torsion_angle,
        'sc_bb_bb_sc_torsion_0': 0.0,
        'bb_bb_bb_sc_torsion_0': 0.0,
        'sc_bb_bb_bb_torsion_0': 0.0
    }

    # Build a coarse grained model
    cgmodel = CGModel(polymer_length=polymer_length,
                      backbone_lengths=backbone_lengths,
                      sidechain_lengths=sidechain_lengths,
                      sidechain_positions=sidechain_positions,
                      masses=masses,
                      sigmas=sigmas,
                      epsilons=epsilons,
                      bond_lengths=bond_lengths,
                      bond_force_constants=bond_force_constants,
                      bond_angle_force_constants=bond_angle_force_constants,
                      torsion_force_constants=torsion_force_constants,
                      equil_bond_angles=equil_bond_angles,
                      equil_torsion_angles=equil_torsion_angles,
                      include_nonbonded_forces=include_nonbonded_forces,
                      include_bond_forces=include_bond_forces,
                      include_bond_angle_forces=include_bond_angle_forces,
                      include_torsion_forces=include_torsion_forces,
                      rosetta_scoring=rosetta_scoring,
                      torsion_periodicities=torsion_periodicities)

    # Get positions by building a pose with PyRosetta
    pyrosetta_sequence = ''.join([
        str('X[' + str(monomer['monomer_name']) + ']')
        for monomer in cgmodel.sequence
    ])
    pose = pyrosetta.pose_from_sequence(pyrosetta_sequence)
    pose.dump_pdb("init.pdb")
    cgmodel.positions = PDBFile("init.pdb").getPositions()
    cgmodel.topology = build_topology(cgmodel)

    return (cgmodel)
configurations,energies = get_decorrelated_samples(replica_positions,replica_energies,temperature_list)

max_num_samples = 0
for traj in configurations:
  if len(traj) > max_num_samples:
    max_num_samples = len(traj)

pitch_kn = np.zeros((len(configurations),max_num_samples))
radius_kn = np.zeros((len(configurations),max_num_samples))
mpt_kn = np.zeros((len(configurations),max_num_samples))
residual_kn = np.zeros((len(configurations),max_num_samples))

for traj_index in range(len(configurations)):
  for pose_index in range(len(configurations[traj_index])):
    cgmodel.positions = configurations[traj_index][pose_index]
    pitch,radius,mpt,residual = get_helical_parameters(cgmodel)
    pitch_kn[traj_index][pose_index] = pitch
    radius_kn[traj_index][pose_index] = radius
    mpt_kn[traj_index][pose_index] = mpt
    residual_kn[traj_index][pose_index] = residual
    
max_pitch,min_pitch=None,None
max_radius,min_radius=None,None
max_mpt,min_mpt=None,None
max_residual,min_residual=None,None

for index in range(len(pitch_kn)):
  for pitch in pitch_kn[index]:
     if max_pitch == None: max_pitch = pitch
     if min_pitch == None: min_pitch = pitch
Пример #9
0
ensemble_list = []

rmsd_cutoff = 2.0

for replica_index in range(len(replica_positions)):
    trajectory = md.load(str("replica_" + str(replica_index + 1) + ".pdb"))
    rmsds = md.rmsd(trajectory, native_structure)
    rmsd_to_helical[replica_index] = rmsds
    for rmsd_index in range(len(rmsd_to_helical[replica_index])):
        if rmsd_to_helical[replica_index][rmsd_index] < rmsd_cutoff:
            rmsd_list.append(rmsd_to_helical[replica_index][rmsd_index])

            ensemble_list.append(replica_positions[replica_index][rmsd_index])

random.shuffle(ensemble_list)

file_index = 1
for pose in ensemble_list:
    if file_index <= 100:
        file_name = str("pose_" + str(file_index) + ".pdb")
        cgmodel.positions = pose
        write_pdbfile_without_topology(cgmodel, file_name)
        target_traj = md.load(file_name)
        aligned_target_traj = target_traj.superpose(native_structure)
        cgmodel.positions = unit.Quantity(aligned_target_traj.xyz[0],
                                          cgmodel.positions.unit)
        write_pdbfile_without_topology(cgmodel, file_name)
        file_index = file_index + 1
    else:
        exit()