def test_random_builder(tmpdir): """See if the random builder can build a simple 1b1s model""" # Coarse grained model settings include_bond_forces = True include_bond_angle_forces = True include_nonbonded_forces = True include_torsion_forces = False constrain_bonds = False random_positions = True # Bond definitions bond_length = 1.5 * 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 = 1000 * unit.kilojoule_per_mole / unit.nanometer / unit.nanometer bond_force_constants = { "bb_bb_bond_force_constant": bond_force_constant, "bb_sc_bond_force_constant": bond_force_constant, "sc_sc_bond_force_constant": bond_force_constant, } # Particle definitions mass = 100.0 * unit.amu r_min = 1.5 * bond_length # Lennard-Jones potential r_min # Factor of /(2.0**(1/6)) is applied to convert r_min to sigma sigma = r_min / (2.0 ** (1.0 / 6.0)) epsilon = 0.5 * unit.kilojoule_per_mole bb = {"particle_type_name": "bb", "sigma": sigma, "epsilon": epsilon, "mass": mass} sc = {"particle_type_name": "sc", "sigma": sigma, "epsilon": epsilon, "mass": mass} # Bond angle definitions bond_angle_force_constant = 100 * unit.kilojoule_per_mole / unit.radian / unit.radian bond_angle_force_constants = { "bb_bb_bb_bond_angle_force_constant": bond_angle_force_constant, "bb_bb_sc_bond_angle_force_constant": bond_angle_force_constant, } # OpenMM requires angle definitions in units of radians bb_bb_bb_equil_bond_angle = 120.0 * unit.degrees bb_bb_sc_equil_bond_angle = 120.0 * unit.degrees equil_bond_angles = { "bb_bb_bb_equil_bond_angle": bb_bb_bb_equil_bond_angle, "bb_bb_sc_equil_bond_angle": bb_bb_sc_equil_bond_angle, } # Torsion angle definitions torsion_force_constant = 20.0 * unit.kilojoule_per_mole torsion_force_constants = { "bb_bb_bb_bb_torsion_force_constant": torsion_force_constant, "bb_bb_bb_sc_torsion_force_constant": torsion_force_constant } bb_bb_bb_bb_torsion_phase_angle = 75.0 * unit.degrees bb_bb_bb_sc_torsion_phase_angle = 75.0 * unit.degrees torsion_phase_angles = { "bb_bb_bb_bb_torsion_phase_angle": bb_bb_bb_bb_torsion_phase_angle, "bb_bb_bb_sc_torsion_phase_angle": bb_bb_bb_sc_torsion_phase_angle } torsion_periodicities = { "bb_bb_bb_bb_torsion_periodicity": 3, "bb_bb_bb_sc_torsion_periodicity": 3} # Monomer definitions A = { "monomer_name": "A", "particle_sequence": [bb, sc], "bond_list": [[0, 1]], "start": 0, "end": 0, } sequence = 5 * [A] # Build a coarse grained model cgmodel = CGModel( particle_type_list=[bb,sc], 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, torsion_phase_angles=torsion_phase_angles, torsion_periodicities=torsion_periodicities, 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, sequence=sequence, constrain_bonds=constrain_bonds, random_positions=random_positions, monomer_types=[A], ) output_directory = tmpdir.mkdir("output") filename = f"{output_directory}/5mer_1b1s_builder_test.pdb" write_pdbfile_without_topology(cgmodel, filename) positions = PDBFile(filename).getPositions() assert len(positions)==10
from simtk.openmm.app.pdbfile import PDBFile from foldamers.cg_model.cgmodel import CGModel from foldamers.parameters.reweight import * from foldamers.parameters.secondary_structure import * from foldamers.thermo.calc import * from foldamers.utilities.plot import plot_distribution from foldamers.utilities.util import random_positions from cg_openmm.build.cg_build import build_topology from cg_openmm.simulation.rep_exch import * grid_size = 6 native_structure_file = str( str(os.getcwd().split('examples/')[0]) + "ensembles/12_1_1_0/helix.pdb") native_structure = PDBFile(native_structure_file).getPositions() # Job settings top_directory = 'output' if not os.path.exists(top_directory): os.mkdir(top_directory) # OpenMM simulation settings print_frequency = 20 # Number of steps to skip when printing output total_simulation_time = 5.0 * unit.nanosecond # Units = picoseconds simulation_time_step = 5.0 * unit.femtosecond total_steps = round(total_simulation_time.__div__(simulation_time_step)) # Yank (replica exchange) simulation settings output_data = str(str(top_directory) + "/output.nc") number_replicas = 30
torsion_force_constant = 0.01 * unit.kilocalorie_per_mole / unit.radian / unit.radian torsion_force_constants = { 'bb_bb_bb_bb_torsion_k': torsion_force_constant, 'sc_bb_bb_sc_torsion_k': torsion_force_constant } bb_bb_bb_bb_equil_torsion_angle = 78.0 * ( 3.14 / 180.0) # OpenMM defaults to units of radians for angle definitions sc_bb_bb_sc_equil_torsion_angle = 120.0 * (3.14 / 180.0) equil_torsion_angles = { 'bb_bb_bb_bb_torsion_0': bb_bb_bb_bb_equil_torsion_angle, 'sc_bb_bb_sc_torsion_0': sc_bb_bb_sc_equil_torsion_angle } torsion_periodicities = {'bb_bb_bb_bb_period': 1, 'sc_bb_bb_sc_period': 2} # Get initial positions from local file positions = PDBFile("helix.pdb").getPositions() # 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,
def test_run_replica_exchange(tmpdir): """ Run a short replica exchange MD simulation of a 24mer 1b1s model Test replica exchange processing (write pdb files) Test heat capacity analysis code Test physical validation code """ global_context_cache.platform = openmm.Platform.getPlatformByName("CPU") # Set output directory # In pytest we need to use a temp directory # tmpdir is a fixture - hence we need to pass it into test function, not import it output_directory = tmpdir.mkdir("output") # Replica exchange simulation settings total_simulation_time = 1.0 * unit.picosecond simulation_time_step = 5.0 * unit.femtosecond total_steps = int(np.floor(total_simulation_time / simulation_time_step)) output_data = os.path.join(output_directory, "output.nc") number_replicas = 4 min_temp = 200.0 * unit.kelvin max_temp = 300.0 * unit.kelvin temperature_list = get_temperature_list(min_temp, max_temp, number_replicas) exchange_frequency = 10 # Number of steps between exchange attempts # Coarse grained model settings include_bond_forces = True include_bond_angle_forces = True include_nonbonded_forces = True include_torsion_forces = True constrain_bonds = False # Bond definitions bond_length = 1.5 * 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 = 1000 * unit.kilojoule_per_mole / unit.nanometer / unit.nanometer bond_force_constants = { "bb_bb_bond_force_constant": bond_force_constant, "bb_sc_bond_force_constant": bond_force_constant, "sc_sc_bond_force_constant": bond_force_constant, } # Particle definitions mass = 100.0 * unit.amu r_min = 1.5 * bond_length # Lennard-Jones potential r_min # Factor of /(2.0**(1/6)) is applied to convert r_min to sigma sigma = r_min / (2.0**(1.0 / 6.0)) epsilon = 0.5 * unit.kilojoule_per_mole bb = { "particle_type_name": "bb", "sigma": sigma, "epsilon": epsilon, "mass": mass } sc = { "particle_type_name": "sc", "sigma": sigma, "epsilon": epsilon, "mass": mass } # Bond angle definitions bond_angle_force_constant = 100 * unit.kilojoule_per_mole / unit.radian / unit.radian bond_angle_force_constants = { "bb_bb_bb_bond_angle_force_constant": bond_angle_force_constant, "bb_bb_sc_bond_angle_force_constant": bond_angle_force_constant, } # OpenMM requires angle definitions in units of radians bb_bb_bb_equil_bond_angle = 120.0 * unit.degrees bb_bb_sc_equil_bond_angle = 120.0 * unit.degrees equil_bond_angles = { "bb_bb_bb_equil_bond_angle": bb_bb_bb_equil_bond_angle, "bb_bb_sc_equil_bond_angle": bb_bb_sc_equil_bond_angle, } # Torsion angle definitions torsion_force_constant = 20.0 * unit.kilojoule_per_mole torsion_force_constants = { "bb_bb_bb_bb_torsion_force_constant": torsion_force_constant, "bb_bb_bb_sc_torsion_force_constant": torsion_force_constant } bb_bb_bb_bb_torsion_phase_angle = 75.0 * unit.degrees bb_bb_bb_sc_torsion_phase_angle = 75.0 * unit.degrees torsion_phase_angles = { "bb_bb_bb_bb_torsion_phase_angle": bb_bb_bb_bb_torsion_phase_angle, "bb_bb_bb_sc_torsion_phase_angle": bb_bb_bb_sc_torsion_phase_angle } torsion_periodicities = { "bb_bb_bb_bb_torsion_periodicity": 3, "bb_bb_bb_sc_torsion_periodicity": 3 } # Monomer definitions A = { "monomer_name": "A", "particle_sequence": [bb, sc], "bond_list": [[0, 1]], "start": 0, "end": 0, } sequence = 24 * [A] pdb_path = os.path.join(structures_path, "24mer_1b1s_initial_structure.pdb") positions = PDBFile(pdb_path).getPositions() # Build a coarse grained model cgmodel = CGModel( particle_type_list=[bb, sc], 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, torsion_phase_angles=torsion_phase_angles, torsion_periodicities=torsion_periodicities, 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, constrain_bonds=constrain_bonds, positions=positions, sequence=sequence, monomer_types=[A], ) 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, exchange_frequency=exchange_frequency, output_data=output_data, ) assert os.path.isfile(f"{output_directory}/output.nc") # Process replica exchange output # 1) With plot production only and print_timing: replica_energies, replica_states, production_start, sample_spacing, n_transit, mixing_stats = process_replica_exchange_data( output_data=output_data, output_directory=output_directory, plot_production_only=True, print_timing=True, ) # 2) With non-default equil_nskip replica_energies, replica_states, production_start, sample_spacing, n_transit, mixing_stats = process_replica_exchange_data( output_data=output_data, output_directory=output_directory, plot_production_only=True, equil_nskip=2, ) # 3) With frame_begin used to circumvent detectEquilibration replica_energies, replica_states, production_start, sample_spacing, n_transit, mixing_stats = process_replica_exchange_data( output_data=output_data, output_directory=output_directory, frame_begin=5, ) # 4) With frame end specified to analyze only the beginning of a trajectory replica_energies, replica_states, production_start, sample_spacing, n_transit, mixing_stats = process_replica_exchange_data( output_data=output_data, output_directory=output_directory, frame_end=25, ) # 5) Without writing .dat file: replica_energies, replica_states, production_start, sample_spacing, n_transit, mixing_stats = process_replica_exchange_data( output_data=output_data, output_directory=output_directory, write_data_file=False, ) # Test pdb writer: make_replica_pdb_files( cgmodel.topology, output_dir=output_directory, ) make_state_pdb_files(cgmodel.topology, output_dir=output_directory) assert os.path.isfile(f"{output_directory}/replica_4.pdb") assert os.path.isfile(f"{output_directory}/state_4.pdb") # With non-default frame_begin, stride, no centering: make_replica_pdb_files(cgmodel.topology, frame_begin=10, frame_stride=2, output_dir=output_directory) make_state_pdb_files(cgmodel.topology, frame_begin=10, frame_stride=2, output_dir=output_directory, center=False) # Test dcd writer: make_replica_dcd_files(cgmodel.topology, timestep=simulation_time_step, time_interval=exchange_frequency, output_dir=output_directory) make_state_dcd_files(cgmodel.topology, timestep=simulation_time_step, time_interval=exchange_frequency, output_dir=output_directory) assert os.path.isfile(f"{output_directory}/replica_4.dcd") assert os.path.isfile(f"{output_directory}/state_4.dcd") # With non-default frame_begin, stride, no centering: make_replica_dcd_files(cgmodel.topology, timestep=simulation_time_step, time_interval=exchange_frequency, frame_begin=10, frame_stride=2, output_dir=output_directory) make_state_dcd_files(cgmodel.topology, timestep=simulation_time_step, time_interval=exchange_frequency, frame_begin=10, frame_stride=2, output_dir=output_directory, center=False)
def build_topology(cgmodel, use_pdbfile=False, pdbfile=None): """ Construct an OpenMM `Topology() <https://simtk.org/api_docs/openmm/api4_1/python/classsimtk_1_1openmm_1_1app_1_1topology_1_1Topology.html>`_ class object for our coarse grained model, :param cgmodel: CGModel() class object :type cgmodel: class :param use_pdbfile: Determines whether or not to use a PDB file in order to generate the Topology(). :type use_pdbfile: Logical :param pdbfile: Name of a PDB file to use when building the topology. :type pdbfile: str :returns: - topology (`Topology() <https://simtk.org/api_docs/openmm/api4_1/python/classsimtk_1_1openmm_1_1app_1_1topology_1_1Topology.html>`_ ) - OpenMM Topology() object :Example: >>> from foldamers.cg_model.cgmodel import CGModel >>> from foldamers.util.iotools import write_pdbfile_without_topology >>> input_pdb = "top.pdb" >>> cgmodel = CGModel() >>> write_pdbfile_without_topology(cgmodel,input_pdb) >>> topology = build_topology(cgmodel,use_pdbfile=True,pdbfile=input_pdb) >>> cgmodel.topology = topology .. warning:: When 'use_pdbfile'=True, this function will use the `PDBFile() <https://simtk.org/api_docs/openmm/api4_1/python/classsimtk_1_1openmm_1_1app_1_1pdbfile_1_1PDBFile.html>`_ class object from OpenMM to build the Topology(). In order for this approach to function correctly, the particle names in the PDB file must match the particle names in the coarse grained model. """ if use_pdbfile == True: if pdbfile == None: write_pdbfile_without_topology(cgmodel, "topology_source.pdb") pdb = PDBFile("topology_source.pdb") topology = pdb.getTopology() os.remove("topology_source.pdb") return (topology) else: pdb = PDBFile(pdbfile) topology = pdb.getTopology() return (topology) topology = Topology() chain = topology.addChain() residue_index = 1 cg_particle_index = 0 for monomer_type in cgmodel.sequence: residue = topology.addResidue(str(residue_index), chain) for backbone_bead in range(monomer_type['backbone_length']): particle_symbol = cgmodel.get_particle_name(cg_particle_index) element = elem.Element.getBySymbol(particle_symbol) particle = topology.addAtom(particle_symbol, element, residue) if backbone_bead == 0 and residue_index != 1: topology.addBond(particle, last_backbone_particle) last_backbone_particle = particle cg_particle_index = cg_particle_index + 1 if backbone_bead in [monomer_type['sidechain_positions']]: for sidechain_bead in range(monomer_type['sidechain_length']): particle_symbol = cgmodel.get_particle_name( cg_particle_index) element = elem.Element.getBySymbol(particle_symbol) particle = topology.addAtom(particle_symbol, element, residue) if sidechain_bead == 0: topology.addBond(particle, last_backbone_particle) if sidechain_bead != 0: topology.addBond(particle, last_sidechain_particle) last_sidechain_particle = particle cg_particle_index = cg_particle_index + 1 residue_index = residue_index + 1 cgmodel.topology = topology verify_topology(cgmodel) return (topology)
def test_run_simulation(tmpdir): """Run a short MD simulation of a 24mer 1b1s model""" # Set output directory # In pytest we need to use a temp directory # tmpdir is a fixture - hence we need to pass it into test function, not import it output_directory = tmpdir.mkdir("output") # OpenMM simulation settings print_frequency = 10 # Number of steps to skip when printing output total_simulation_time = 1.0 * unit.picosecond simulation_time_step = 5.0 * unit.femtosecond total_steps = int(np.floor(total_simulation_time / simulation_time_step)) temperature = 200 * unit.kelvin friction = 1.0 / unit.picosecond # Coarse grained model settings include_bond_forces = True include_bond_angle_forces = True include_nonbonded_forces = True include_torsion_forces = True constrain_bonds = False # Bond definitions bond_length = 1.5 * 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 = 1000 * unit.kilojoule_per_mole / unit.nanometer / unit.nanometer bond_force_constants = { "bb_bb_bond_force_constant": bond_force_constant, "bb_sc_bond_force_constant": bond_force_constant, "sc_sc_bond_force_constant": bond_force_constant, } # Particle definitions mass = 100.0 * unit.amu r_min = 1.5 * bond_length # Lennard-Jones potential r_min # Factor of /(2.0**(1/6)) is applied to convert r_min to sigma sigma = r_min / (2.0**(1.0 / 6.0)) epsilon = 0.5 * unit.kilojoule_per_mole bb = { "particle_type_name": "bb", "sigma": sigma, "epsilon": epsilon, "mass": mass } sc = { "particle_type_name": "sc", "sigma": sigma, "epsilon": epsilon, "mass": mass } # Bond angle definitions bond_angle_force_constant = 100 * unit.kilojoule_per_mole / unit.radian / unit.radian bond_angle_force_constants = { "bb_bb_bb_bond_angle_force_constant": bond_angle_force_constant, "bb_bb_sc_bond_angle_force_constant": bond_angle_force_constant, } # OpenMM requires angle definitions in units of radians bb_bb_bb_equil_bond_angle = 120.0 * unit.degrees bb_bb_sc_equil_bond_angle = 120.0 * unit.degrees equil_bond_angles = { "bb_bb_bb_equil_bond_angle": bb_bb_bb_equil_bond_angle, "bb_bb_sc_equil_bond_angle": bb_bb_sc_equil_bond_angle, } # Torsion angle definitions torsion_force_constant = 20.0 * unit.kilojoule_per_mole torsion_force_constants = { "bb_bb_bb_bb_torsion_force_constant": torsion_force_constant, "bb_bb_bb_sc_torsion_force_constant": torsion_force_constant } bb_bb_bb_bb_torsion_phase_angle = 75.0 * unit.degrees bb_bb_bb_sc_torsion_phase_angle = 75.0 * unit.degrees torsion_phase_angles = { "bb_bb_bb_bb_torsion_phase_angle": bb_bb_bb_bb_torsion_phase_angle, "bb_bb_bb_sc_torsion_phase_angle": bb_bb_bb_sc_torsion_phase_angle } torsion_periodicities = { "bb_bb_bb_bb_torsion_periodicity": 3, "bb_bb_bb_sc_torsion_periodicity": 3 } # Monomer definitions A = { "monomer_name": "A", "particle_sequence": [bb, sc], "bond_list": [[0, 1]], "start": 0, "end": 0, } sequence = 24 * [A] pdb_path = os.path.join(structures_path, "24mer_1b1s_initial_structure.pdb") positions = PDBFile(pdb_path).getPositions() # Build a coarse grained model cgmodel = CGModel( particle_type_list=[bb, sc], 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, torsion_phase_angles=torsion_phase_angles, torsion_periodicities=torsion_periodicities, 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, constrain_bonds=constrain_bonds, positions=positions, sequence=sequence, monomer_types=[A], ) run_simulation( cgmodel, total_simulation_time, simulation_time_step, temperature, friction=friction, print_frequency=print_frequency, output_directory=output_directory, ) assert os.path.isfile(f"{output_directory}/simulation.dat") assert os.path.isfile(f"{output_directory}/simulation.pdb")
# Torsion angle definitions torsion_force_constant = 0.0001 * unit.kilocalorie_per_mole / unit.radian / unit.radian torsion_force_constants = { "bb_bb_bb_bb_torsion_k": torsion_force_constant } # ,'sc_bb_bb_sc_torsion_k': torsion_force_constant} bb_bb_bb_bb_equil_torsion_angle = 78.0 * ( 3.14 / 180.0) # OpenMM defaults to units of radians for angle definitions # sc_bb_bb_sc_equil_torsion_angle = 110.0 * (3.14/180.0) equil_torsion_angles = { "bb_bb_bb_bb_torsion_0": bb_bb_bb_bb_equil_torsion_angle } # ,'sc_bb_bb_sc_torsion_0': sc_bb_bb_sc_equil_torsion_angle} torsion_periodicities = {"bb_bb_bb_bb_period": 1} # ,'sc_bb_bb_sc_period': 2} # Initiate cgmodel using positions from local file positions = PDBFile("init.pdb").getPositions() native_structure = positions 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, torsion_force_constants=torsion_force_constants, equil_torsion_angles=equil_torsion_angles,
import os, timeit import numpy as np import matplotlib.pyplot as pyplot from simtk import unit from simtk.openmm.app.pdbfile import PDBFile from foldamers.cg_model.cgmodel import CGModel from foldamers.parameters.secondary_structure import * positions = PDBFile(str(str(os.getcwd().split('examples')[0])+"ensembles/12_1_1_0/helix.pdb")).getPositions() cgmodel = CGModel(positions=positions) pitch,radius,monomers_per_turn,residual = get_helical_parameters(cgmodel) print(pitch,radius,monomers_per_turn,residual) cgmodel = orient_along_z_axis(cgmodel) show_helical_fit(cgmodel) p2 = calculate_p2(cgmodel) print(p2) exit()
def test_sums_periodic_torsions_5(): # Test cg_model with sums of periodic torsions - test 5 # Two periodic torsion terms, parameters input as quantities with list values # Parameters are applied to all torsion types using the default input method # Coarse grained model settings include_bond_forces = True include_bond_angle_forces = True include_nonbonded_forces = True include_torsion_forces = True constrain_bonds = False # Bond definitions bond_length = 1.5 * 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 = 1000 * unit.kilojoule_per_mole / unit.nanometer / unit.nanometer bond_force_constants = { "bb_bb_bond_force_constant": bond_force_constant, "bb_sc_bond_force_constant": bond_force_constant, "sc_sc_bond_force_constant": bond_force_constant, } # Particle definitions mass = 100.0 * unit.amu r_min = 1.5 * bond_length # Lennard-Jones potential r_min # Factor of /(2.0**(1/6)) is applied to convert r_min to sigma sigma = r_min / (2.0**(1.0 / 6.0)) epsilon = 0.5 * unit.kilojoule_per_mole bb = { "particle_type_name": "bb", "sigma": sigma, "epsilon": epsilon, "mass": mass } sc = { "particle_type_name": "sc", "sigma": sigma, "epsilon": epsilon, "mass": mass } # Bond angle definitions bond_angle_force_constant = 100 * unit.kilojoule_per_mole / unit.radian / unit.radian bond_angle_force_constants = { "bb_bb_bb_bond_angle_force_constant": bond_angle_force_constant, "bb_bb_sc_bond_angle_force_constant": bond_angle_force_constant, } # OpenMM requires angle definitions in units of radians bb_bb_bb_equil_bond_angle = 120.0 * unit.degrees bb_bb_sc_equil_bond_angle = 120.0 * unit.degrees equil_bond_angles = { "bb_bb_bb_equil_bond_angle": bb_bb_bb_equil_bond_angle, "bb_bb_sc_equil_bond_angle": bb_bb_sc_equil_bond_angle, } # Torsion angle definitions torsion_force_constants = { "default_torsion_force_constant": [5, 10] * unit.kilojoule_per_mole, } torsion_phase_angles = { "default_torsion_phase_angle": [0, 180] * unit.degrees, } torsion_periodicities = { "default_torsion_periodicity": [1, 3], } # Monomer definitions A = { "monomer_name": "A", "particle_sequence": [bb, sc], "bond_list": [[0, 1]], "start": 0, "end": 0, } sequence = 24 * [A] pdb_path = os.path.join(data_path, "24mer_1b1s_initial_structure.pdb") positions = PDBFile(pdb_path).getPositions() # Build a coarse grained model cgmodel = CGModel( particle_type_list=[bb, sc], 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, torsion_phase_angles=torsion_phase_angles, torsion_periodicities=torsion_periodicities, 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, constrain_bonds=constrain_bonds, positions=positions, sequence=sequence, monomer_types=[A], ) # Check the number of periodic torsions terms: n_torsion_forces = cgmodel.system.getForces()[3].getNumTorsions() assert n_torsion_forces == 176
def create_cgmodel(): # Coarse grained model settings include_bond_forces = True include_bond_angle_forces = True include_nonbonded_forces = True include_torsion_forces = True constrain_bonds = False # Bond definitions bond_length = 1.5 * 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 = 1000 * unit.kilojoule_per_mole / unit.nanometer / unit.nanometer bond_force_constants = { "bb_bb_bond_force_constant": bond_force_constant, "bb_sc_bond_force_constant": bond_force_constant, "sc_sc_bond_force_constant": bond_force_constant, } # Particle definitions mass = 100.0 * unit.amu r_min = 1.5 * bond_length # Lennard-Jones potential r_min # Factor of /(2.0**(1/6)) is applied to convert r_min to sigma sigma = r_min / (2.0**(1.0 / 6.0)) epsilon = 0.5 * unit.kilojoule_per_mole bb = { "particle_type_name": "bb", "sigma": sigma, "epsilon": epsilon, "mass": mass } sc = { "particle_type_name": "sc", "sigma": sigma, "epsilon": epsilon, "mass": mass } # Bond angle definitions bond_angle_force_constant = 100 * unit.kilojoule_per_mole / unit.radian / unit.radian bond_angle_force_constants = { "bb_bb_bb_bond_angle_force_constant": bond_angle_force_constant, "bb_bb_sc_bond_angle_force_constant": bond_angle_force_constant, } # OpenMM requires angle definitions in units of radians bb_bb_bb_equil_bond_angle = 120.0 * unit.degrees bb_bb_sc_equil_bond_angle = 120.0 * unit.degrees equil_bond_angles = { "bb_bb_bb_equil_bond_angle": bb_bb_bb_equil_bond_angle, "bb_bb_sc_equil_bond_angle": bb_bb_sc_equil_bond_angle, } # Torsion angle definitions torsion_force_constant = 20.0 * unit.kilojoule_per_mole torsion_force_constants = { "bb_bb_bb_bb_torsion_force_constant": torsion_force_constant, "bb_bb_bb_sc_torsion_force_constant": torsion_force_constant } bb_bb_bb_bb_torsion_phase_angle = 75.0 * unit.degrees bb_bb_bb_sc_torsion_phase_angle = 75.0 * unit.degrees torsion_phase_angles = { "bb_bb_bb_bb_torsion_phase_angle": bb_bb_bb_bb_torsion_phase_angle, "bb_bb_bb_sc_torsion_phase_angle": bb_bb_bb_sc_torsion_phase_angle } torsion_periodicities = { "bb_bb_bb_bb_torsion_periodicity": 3, "bb_bb_bb_sc_torsion_periodicity": 3 } # Monomer definitions A = { "monomer_name": "A", "particle_sequence": [bb, sc], "bond_list": [[0, 1]], "start": 0, "end": 0, } sequence = 24 * [A] pdb_path = os.path.join(data_path, "24mer_1b1s_initial_structure.pdb") positions = PDBFile(pdb_path).getPositions() # Build a coarse grained model cgmodel = CGModel( particle_type_list=[bb, sc], 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, torsion_phase_angles=torsion_phase_angles, torsion_periodicities=torsion_periodicities, 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, constrain_bonds=constrain_bonds, positions=positions, sequence=sequence, monomer_types=[A], ) return cgmodel