def generate_topology(self): """Creates a one-atom, dummy trajectory and topology for the randomwalk system using the mdtraj package. Then creates a JSON format for the topology. This JSON string is used in making the WepyHDF5 reporter. Returns ------- topology: str JSON string representing the topology of system being simulated. """ n_atoms = 1 data = [] for i in range(n_atoms): data.append( dict(serial=i, name="H", element="H", resSeq=i + 1, resName="UNK", chainID=0)) data = pd.DataFrame(data) xyz = np.zeros((1, 1, 3)) unitcell_lengths = 0.943 * np.ones((1, 3)) unitcell_angles = 90 * np.ones((1, 3)) top = mdj.Topology.from_dataframe(data, bonds=np.zeros((0, 2), dtype='int')) json_top_str = mdtraj_to_json_topology(top) return json_top_str
def json_top(cls): test_sys = cls.TEST_SYS() # convert to a JSON top json_top = mdtraj_to_json_topology( mdj.Topology.from_openmm(test_sys.topology)) return json_top
# between two walkers, for our scorer class distance = PairDistance() ## Resampler resampler = WExploreResampler(distance=distance, init_state=init_state, max_region_sizes=MAX_REGION_SIZES, max_n_regions=MAX_N_REGIONS, pmin=PMIN, pmax=PMAX) ## Boundary Conditions # the mdtraj here is needed for the distance function mdtraj_topology = mdj.Topology.from_openmm(test_sys.topology) json_str_top = mdtraj_to_json_topology(mdtraj_topology) # initialize the unbinding boundary conditions ubc = UnbindingBC(cutoff_distance=CUTOFF_DISTANCE, initial_state=init_state, topology=json_str_top, ligand_idxs=np.array(test_sys.ligand_indices), receptor_idxs=np.array(test_sys.receptor_indices)) ## Reporters # make a dictionary of units for adding to the HDF5 units = dict(UNIT_NAMES) # open it in truncate mode first, then switch after first run hdf5_reporter = WepyHDF5Reporter(file_path=hdf5_path,
charmm_psf_path = osp.join(inputs_dir, charmm_psf_filename) pdb_path = osp.join(inputs_dir, starting_coords_pdb) charmm_param_paths = [osp.join(inputs_dir, filename) for filename in charmm_param_files] json_top_path = osp.join(inputs_dir, json_top_filename) omm_state_path = osp.join(inputs_dir, omm_state_filename) # load the charmm file for the topology psf = omma.CharmmPsfFile(charmm_psf_path) # load the coordinates pdb = mdj.load_pdb(pdb_path) # convert the mdtraj topology to a json one top_str = mdtraj_to_json_topology(pdb.topology) # write the JSON topology out with open(json_top_path, mode='w') as json_wf: json_wf.write(top_str) # to use charmm forcefields get your parameters params = omma.CharmmParameterSet(*charmm_param_paths) # set the box size lengths and angles lengths = [8.2435*unit.nanometer for i in range(3)] angles = [90*unit.degree for i in range(3)] psf.setBox(*lengths, *angles) # create a system using the topology method giving it a topology and
get_state_kwargs = dict(GET_STATE_KWARG_DEFAULTS) random_pos = random.sample(range(1000), n_walkers) walker_pos = pickle.load(open(f'inputs/{epsilon}eps_init_positions.pkl', 'rb')) for i in range(n_walkers): # initiate the test system test_sys = LennardJonesPair(epsilon=epsilon * unit.kilocalories_per_mole) # change the box size # Vectors set in Vec3. unit=nanometers test_sys.system.setDefaultPeriodicBoxVectors([4, 0, 0], [0, 4, 0], [0, 0, 4]) system = test_sys.system omm_topology = test_sys.topology mdj_top = mdj.Topology.from_openmm(omm_topology) json_top = mdtraj_to_json_topology(mdj_top) # make the integrator and barostat integrator = omm.LangevinIntegrator(TEMPERATURE, FRICTION_COEFFICIENT, STEP_SIZE) # build the harmonic force total_lj = CustomBondForce("0.5*k*(r-r0)^2") total_lj.addPerBondParameter('k') total_lj.addPerBondParameter('r0') # param [0] is the spring constant, param [1] is the init distance (nm) total_lj.addBond(0, 1, [2000, 0.320 * unit.nanometer]) system.addForce(total_lj) # load positions (randomy selects unrepreated position pairs from # a previously generated, well equilibrated system)
# distance from the ligand in the crystal structure used to determine # the binding site, used to align ligands in the Unbinding distance # metric BINDING_SITE_CUTOFF = 0.8 # in nanometers # the residue id for the ligand so that it's indices can be determined LIG_RESID = "2RV" # Initial experimental coordinates PDB = mdj.load_pdb(pdb_path) EXPERIMENTAL_POSITIONS = PDB.xyz[0] EXPERIMENTAL_OMM_POSITIONS = PDB.openmm_positions(frame=0) # topologies TOP_MDTRAJ = PDB.topology TOP_JSON = mdtraj_to_json_topology(TOP_MDTRAJ) # the protein, binding site, and ligand atoms BS_IDXS = binding_site_atoms(TOP_MDTRAJ, LIG_RESID, EXPERIMENTAL_POSITIONS) LIG_IDXS = ligand_idxs(TOP_MDTRAJ, LIG_RESID) PROT_IDXS = protein_idxs(TOP_MDTRAJ) # reporting parameters # these are the properties of the states (i.e. from OpenMM) which will # be saved into the HDF5 SAVE_FIELDS = ('positions', 'box_vectors', 'velocities') # these are the names of the units which will be stored with each # field in the HDF5 UNITS = UNIT_NAMES
import numpy as np import pandas as pd import tables as pytables import mdtraj as mdj from wepy.util.mdtraj import mdtraj_to_json_topology from wepy.util.json_top import json_top_chain_df, json_top_residue_df, json_top_atom_df traj = mdj.load('../lysozyme_pxylene.pdb') if osp.exists("outputs"): shutil.rmtree("outputs") os.makedirs("outputs") # the JSON format json_top = mdtraj_to_json_topology(traj.top) with open('outputs/lysozyme_pxylene.top.json', 'w') as wf: wf.write(json_top) # FASTA residue sequence fasta_str = traj.top.to_fasta(chain=0) with open('outputs/lysozyme_pxylene.res.fasta', 'w') as wf: wf.write(fasta_str) ## topology tables # Bonds # you can get a table using mdtraj, but we just use the bonds here mdj_atoms_df, bonds = traj.top.to_dataframe()