def get_xtc_time(filename): """ Returns the starting time and first timestep of the given xtc traj """ f = xtc.XTCFile() f.read(filename, start=0, stop=2) time = f.get_time() time[1] -= time[0] return time
def test_PDBx_consistency(format): pdbx_file = pdbx.PDBxFile() pdbx_file.read(join(data_dir, "1l2y.cif")) array1 = pdbx.get_structure(pdbx_file) template = pdbx.get_structure(pdbx_file, model=1) if format == "trr": traj_file = trr.TRRFile() traj_file.read(join(data_dir, "1l2y.trr")) if format == "xtc": traj_file = xtc.XTCFile() traj_file.read(join(data_dir, "1l2y.xtc")) array2 = traj_file.get_structure(template) for cat in array1. get_annotation_categories(): assert array1.get_annotation(cat).tolist() == \ array2.get_annotation(cat).tolist() assert array1.coord == pytest.approx(array2.coord)
# The structure still has water and ions, that are not needed for our # calculations, we are only interested in the protein itself # These are removed for the sake of computational speed using a boolean # mask protein_mask = struc.filter_amino_acids(protein) template = protein[protein_mask] # We could have loaded the trajectory also with # 'strucio.load_structure()', but in this case we only want to load # those coordinates that belong to the already selected atoms of the # template structure. # Hence, we use the 'XTCFile' class directly to load the trajectory # This gives us the additional option that allows us to select the # coordinates belonging to the amino acids. print(" .. loading trajectory ...") xtc_file = xtc.XTCFile() #xtc_file.read(traj_file_path, 0, 10, atom_i=np.where(protein_mask)[0]) xtc_file.read(traj_file_path, atom_i=np.where(protein_mask)[0]) #xtc_file.read(traj_file_path) trajectory = xtc_file.get_structure(template) print(" ... done ... ") #trajectory = struc.remove_pbc(trajectory) print(trajectory[0].coord) trajectory_kinase_left = trajectory[:, trajectory.chain_id == "A"] trajectory_kinase_right = trajectory[:, trajectory.chain_id == "D"] print(trajectory_kinase_left.coord.shape[0])
def write_to_xtc(array_stack, outfile): """ """ xtcfile = bxtc.XTCFile() xtcfile.set_coord(array_stack) xtcfile.write(outfile)
active_sites = traj[:,mask_active_site,:] active_sites = np.mean(active_sites,axis = 1) coords_exit = traj[:,mask_exit,:] coords_exit = np.mean(coords_exit,axis = 1) density = np.empty((traj.shape[0],len(radius))) for j,r in enumerate(radius): for i in range(traj.shape[0]): n_atoms = np.where(in_cylinder(coords_exit[i],active_sites[i],r,traj[i]))[0].shape volume = np.linalg.norm(coords_exit[i] - active_sites[i]) * np.pi * r**2 density[i,j] = n_atoms / volume return density radius = [6,8,9,10,11,12,13,14,15,16] struct = PDB.PDBFile() struct.read("../md_simulations/kinase_dimer.pdb") struct = struct.get_structure()[0] traj = XTC.XTCFile() traj.read("../md_simulations/kinase_dimer_nopbc_cluster_fit.xtc") traj = traj.get_coord() density_a = calculate_densities(struct,traj,"A",radius) density_data_a = pd.DataFrame(data=density_a,columns = [str(i) for i in radius]) density_data_a.to_csv("density_data_kinase_a.csv") density_d = calculate_densities(struct,traj,"D",radius) density_data_d = pd.DataFrame(data=density_d,columns = [str(i) for i in radius]) density_data_d.to_csv("density_data_kinase_d.csv")
# These can be extracted as :class:`ndarray` with the # :func:`get_coord()` method. import requests import biotite import biotite.structure.io.xtc as xtc # Download 1L2Y as XTC file for demonstration purposes xtc_file_path = biotite.temp_file("xtc") with open(xtc_file_path, "bw") as file: response = requests.get( "https://raw.githubusercontent.com/biotite-dev/biotite/master/" "tests/structure/data/1l2y.xtc") file.write(response.content) traj_file = xtc.XTCFile() traj_file.read(xtc_file_path) coord = traj_file.get_coord() print(coord.shape) ######################################################################## # If only an excerpt of frames is desired, the behavior of # :func:`read()` function can be customized with the `start`, `stop` and # `step` parameters. traj_file = xtc.XTCFile() # Read only every second frame traj_file.read(xtc_file_path, step=2) coord = traj_file.get_coord() print(coord.shape)
distance_matrices = None with Pool() as p: distance_matrices = p.map(f_worker, lines) return np.array(distance_matrices) if __name__ == "__main__": # take first output structure as structure to align to template_dimer = strucio.load_structure( "dimer_refined/pk_mono_sur_di_0001_000001_0001.pdb") print(" ... loading XTC files ... ") xtc_dimer = xtc.XTCFile() xtc_dimer.read("dimers_ordered_by_cleaned.xtc") #, 1, 10) print(" ... done ... ") print("") print("") trajectory_dimer = xtc_dimer.get_structure(template_dimer) pkcs_start = trajectory_dimer[0][trajectory_dimer[0].chain_id == 'A'] pkcs_start = pkcs_start[pkcs_start.atom_name == "CA"] trajectory_dimer, transform = struc.superimpose( trajectory_dimer[0], trajectory_dimer, (trajectory_dimer[0].chain_id == 'A') & (trajectory_dimer[0].atom_name == 'CA')) trajectory_dimer_ca = trajectory_dimer[:,