def test_read_one(self): reader = Reader().readThisFile('data/amber_mini.pdb') coordinates = reader.read() self.assertEqual(148, reader.numberOfAtoms) self.assertEqual(3, reader.numberOfFrames) numpy.testing.assert_almost_equal(testPdbReader.mini_all_coords, coordinates, 12)
def test_read_multiple_only_CA(self): reader = Reader().readThisFile('data/amber_mini.pdb').andThisOtherFile('data/amber_mini.pdb').gettingOnlyCAs() coordinates = reader.read() self.assertEqual(9, reader.numberOfAtoms) self.assertEqual(6, reader.numberOfFrames) coord_shape = coordinates.shape self.assertEqual(coord_shape[0]*coord_shape[1]*coord_shape[2],9*6*3) numpy.testing.assert_almost_equal(numpy.reshape(self.mini_CA_coords,3*9*3), numpy.reshape(coordinates,6*9*3)[0:9*3*3], 10) numpy.testing.assert_almost_equal(numpy.reshape(self.mini_CA_coords,3*9*3), numpy.reshape(coordinates,6*9*3)[9*3*3:], 10)
def test_read_multiple(self): reader = Reader().readThisFile('data/amber_mini.pdb').andThisOtherFile('data/amber_mini.pdb') coordinates = reader.read() self.assertEqual(148, reader.numberOfAtoms) self.assertEqual(6, reader.numberOfFrames) coord_shape = coordinates.shape self.assertEqual(coord_shape[0]*coord_shape[1]*coord_shape[2],148*6*3) numpy.testing.assert_almost_equal(numpy.reshape(self.mini_all_coords,3*148*3), numpy.reshape(coordinates,148*6*3)[0:148*3*3], 10) numpy.testing.assert_almost_equal(numpy.reshape(self.mini_all_coords,3*148*3), numpy.reshape(coordinates,148*6*3)[148*3*3:], 10)
def test_read_multiple_only_CA(self): reader = Reader().readThisFile('data/amber_mini.pdb').andThisOtherFile( 'data/amber_mini.pdb').gettingOnlyCAs() coordinates = reader.read() self.assertEqual(9, reader.numberOfAtoms) self.assertEqual(6, reader.numberOfFrames) coord_shape = coordinates.shape self.assertEqual(coord_shape[0] * coord_shape[1] * coord_shape[2], 9 * 6 * 3) numpy.testing.assert_almost_equal( numpy.reshape(self.mini_CA_coords, 3 * 9 * 3), numpy.reshape(coordinates, 6 * 9 * 3)[0:9 * 3 * 3], 10) numpy.testing.assert_almost_equal( numpy.reshape(self.mini_CA_coords, 3 * 9 * 3), numpy.reshape(coordinates, 6 * 9 * 3)[9 * 3 * 3:], 10)
def test_read_multiple(self): reader = Reader().readThisFile('data/amber_mini.pdb').andThisOtherFile( 'data/amber_mini.pdb') coordinates = reader.read() self.assertEqual(148, reader.numberOfAtoms) self.assertEqual(6, reader.numberOfFrames) coord_shape = coordinates.shape self.assertEqual(coord_shape[0] * coord_shape[1] * coord_shape[2], 148 * 6 * 3) numpy.testing.assert_almost_equal( numpy.reshape(self.mini_all_coords, 3 * 148 * 3), numpy.reshape(coordinates, 148 * 6 * 3)[0:148 * 3 * 3], 10) numpy.testing.assert_almost_equal( numpy.reshape(self.mini_all_coords, 3 * 148 * 3), numpy.reshape(coordinates, 148 * 6 * 3)[148 * 3 * 3:], 10)
def test_read_one_only_CA(self): reader = Reader().readThisFile('data/amber_mini.pdb').gettingOnlyCAs() coordinates = reader.read() self.assertEqual(9, reader.numberOfAtoms) self.assertEqual(3, reader.numberOfFrames) numpy.testing.assert_almost_equal(self.mini_CA_coords, coordinates, 10)
import time import os import bz2 from pyRMSD.utils.proteinReading import Reader if __name__ == '__main__': using_cuda = "QCP_CUDA_CALCULATOR" in pyRMSD.RMSDCalculator.availableCalculators() ###################### # BENCHMARKING ###################### print "Loading file..." t1 = time.time() print "\tUncompressing..." open("tmp_amber_long.pdb","w").write(bz2.BZ2File("data/amber_long.pdb.tar.bz2").read()) print "\tLoading..." reader = Reader().readThisFile('tmp_amber_long.pdb').gettingOnlyCAs() coordsets = reader.read() number_of_atoms = reader.numberOfAtoms number_of_conformations = reader.numberOfFrames os.system("rm tmp_amber_long.pdb") print "\tDeleting temporary file" t2 = time.time() print 'Loading took %0.3f s' % (t2-t1) ####################### # CALCULATION ####################### types = pyRMSD.RMSDCalculator.availableCalculators() DEFAULT_PRECISSION = 1e-8 precissions = collections.defaultdict(lambda:DEFAULT_PRECISSION)
expect_script_str = ("".join( open("data/expect_script", "r").readlines())) % (TRAJECTORY_FILE, TRAJECTORY_FILE) open("data/expect_script_tmp", "w").write(expect_script_str) # Use 'expect' to spawn the program start_t = time.time() subprocess.call(["expect", "data/expect_script_tmp"]) # Load the matrix g_rmsd_matrix = XPMConverter().convert(open("data/matrix.xpm", "r")) stop_t = time.time() print "g_rms's computation time:", stop_t - start_t os.system("rm data/matrix.xpm data/rmsd.xvg data/expect_script_tmp") # Computation with pyRMSD, g_rms uses KABSCH's start_t = time.time() coordinates = Reader().readThisFile(TRAJECTORY_FILE).read() RMSDCalculator(coordinates, "KABSCH_SERIAL_CALCULATOR").oneVsFollowing( 0) # This is to mimic g_rmsd pipeline pyrmsd_rmsd_values = RMSDCalculator( coordinates, "QTRFIT_SERIAL_CALCULATOR").pairwiseRMSDMatrix() stop_t = time.time() print "pyRMSD's computation time:", stop_t - start_t # Convert g_rmsd matrix to 'condensed' dim = len(g_rmsd_matrix) c_m_values = [] for i in range(dim - 1): for j in range(i + 1, dim): c_m_values.append(g_rmsd_matrix[i][j]) rmsd = numpy.sqrt((
from nma_algo_char.mode_application_analysis import process_energy_differences if __name__ == '__main__': parser = OptionParser() parser.add_option("--type", dest="sim_type") parser.add_option("-f", dest="work_folder") parser.add_option("-o", dest="open_pdb_file") parser.add_option("-c", dest="closed_pdb_file") parser.add_option("-t", type="int", dest="temperature") (options, args) = parser.parse_args() open_coords = Reader().readThisFile(options.open_pdb_file).gettingOnlyCAs().read() closed_coords = Reader().readThisFile(options.closed_pdb_file).gettingOnlyCAs().read() # Get eigenvectors, used modes and coordinates eigenfile = {"CC": "original_modes.1.nmd", "IC":"original_modes_cc.1.nmd"} eigenvalues, eigenvectors, _ = ProdyNMDParser.read(os.path.join(options.work_folder,"info", eigenfile[options.sim_type])) raw_data, min_len = load_single_proc_data(options.sim_type, os.path.join(options.work_folder,"info")) mode_parser = LineParser("Picked", 2, int) for line in open(os.path.join(options.work_folder, "log.txt")): mode_parser.parse_line(line) raw_data["picked_mode"] = numpy.array(mode_parser.data)[:min_len] frequencies = Counter(raw_data["picked_mode"]) energy_increments = process_energy_differences(raw_data)[1:] mc = MetropolisMCSimulator(energy_increments) who_is_accepted = mc.who_is_accepted(options.temperature) acc_frequencies = Counter(raw_data["picked_mode"][who_is_accepted])
def ref_rmsf_calculation(reftraj): coords = Reader().readThisFile(reftraj).gettingOnlyCAs().read() return coords_rmsf(coords)
def get_coordinates(trajectories, skip, max_frames): all_coordsets = [] for traj_path in trajectories: coords = Reader().readThisFile(traj_path).gettingOnlyCAs().read() all_coordsets.append(coords[skip:min(len(coords), max_frames + skip)]) return all_coordsets