def test_init(self): m = SASModel() m.read(self.testfile) n = SASModel(self.testfile) param1 = m.rfactor param2 = n.rfactor self.assertEqual(param1, param2, msg="pdb file not read correctly")
def test_read(self): inputfiles = self.inputfiles average = AverModels(inputfiles, self.grid.coordknots) models = [SASModel(inputfiles[1]), SASModel(inputfiles[0])] average.read_files(reference=1) diff = 0.0 for i in range(len(inputfiles)): diff += (models[i].atoms - average.models[i].atoms).max() self.assertAlmostEqual(diff, 0.0, 10, msg="Files not read properly")
def test_distance(self): m = SASModel() n = SASModel() m.read(self.testfile1) n.read(self.testfile2) f_np = m.dist(n, m.atoms, n.atoms, False) f_cy = m.dist(n, m.atoms, n.atoms, True) self.assertAlmostEqual(f_np, f_cy, 10, "distance is the same %s!=%s" % (f_np, f_cy))
def test_dist_move(self): m = assign_random_mol() n = SASModel(m.atoms) m.canonical_parameters() n.canonical_parameters() if abs(n.atoms - m.atoms).max() != 0: logger.error("molecules are different") p0 = m.can_param dist_after_mvt = m.dist_after_movement(p0, n, [1, 1, 1]) self.assertEqual(dist_after_mvt, 0, msg="NSD different of 0: %s!=0" % (dist_after_mvt))
def test_same(self): m = SASModel() n = SASModel() m.read(self.testfile1) n.read(self.testfile1) numpy.random.shuffle(n.atoms) f_np = m.dist(n, m.atoms, n.atoms, False) f_cy = m.dist(n, m.atoms, n.atoms, True) self.assertAlmostEqual(f_np, 0, 10, "NSD not nul with np") self.assertAlmostEqual(f_cy, 0, 10, "NSD not nul with cy")
def spatial_extent(self): """ Calculate the maximal extent of input models :return self.size: 6-list with x,y,z max and then x,y,z min """ atoms = [] models_fineness = [] for files in self.inputs: m = SASModel(files) if len(atoms) == 0: atoms = m.atoms else: atoms = numpy.append(atoms, m.atoms, axis=0) models_fineness.append(m.fineness) mean_fineness = sum(models_fineness) / len(models_fineness) coordmin = atoms.min(axis=0) - mean_fineness coordmax = atoms.max(axis=0) + mean_fineness self.size = [ coordmax[0], coordmax[1], coordmax[2], coordmin[0], coordmin[1], coordmin[2] ] return self.size
def test_reverse_transform(self): m = assign_random_mol() n = SASModel(m.atoms) m.canonical_parameters() m.atoms = m.transform(m.can_param, [1, 1, 1], reverse=None) m.atoms = m.transform(m.can_param, [1, 1, 1], reverse=True) dist = m.dist(n, m.atoms, n.atoms) self.assertAlmostEqual(dist, 0.0, 10, msg="pb with reverse transformation : %s != 0.0" % dist)
def test_makegrid(self): grid = self.grid lattice = grid.make_grid() m = SASModel(lattice) self.assertAlmostEqual(m.fineness, 2 * grid.radius, 10, msg="grid do not have the computed radius")
def assign_random_mol(inf=None, sup=None): if not inf: inf = 0 if not sup: sup = 100 molecule = numpy.random.randint(inf, sup, size=400).reshape(100, 4).astype(float) molecule[:, -1] = 1.0 m = SASModel(molecule) return m
def assign_models(self): """ Create SASModels from pdb files saved in self.inputfiles and saved them in self.models. Center of mass, inertia tensor and canonical parameters are computed for each SASModel. :return self.models: list of SASModel """ for inputpdb in self.inputfiles: model = SASModel() model.read(inputpdb) model.centroid() model.inertiatensor() model.canonical_parameters() self.models.append(model) if len(self.inputfiles) != len(self.models): logger.error("Problem of assignment\n%s models for %s files" % (len(self.models), len(self.inputfiles))) return self.models
def read_files(self, reference=None): """ Read all the pdb file in the inputfiles list, creating SASModels. The SASModels created are save in a list, the reference model is the first model in the list. :param reference: position of the reference model file in the inputfiles list """ ref = reference if reference is not None else 0 inputfiles = self.inputfiles models = [] models.append(SASModel(inputfiles[ref])) for i in range(len(inputfiles)): if i==ref: continue else: models.append(SASModel(inputfiles[i])) self.models = models return models
def test_same(self): m = SASModel() m.read(self.testfile) m.save(self.outfile) infile = open(self.testfile).read() outfile = open(self.outfile).read() self.assertEqual(infile, outfile, msg="file content is the same")
def test_gridsize(self): inputfiles = self.inputfiles grid = self.grid size = grid.spatial_extent() coordmax = numpy.array([size[0:3]], dtype="float") coordmin = numpy.array([size[3:6]], dtype="float") pb = 0 for i in inputfiles: m = SASModel(i) a = coordmin + m.atoms[:, 0:3] b = m.atoms[:, 0:3] - coordmax if (a >= 0.0).any() or (b >= 0.0).any(): pb += 1 self.assertEqual(pb, 0, msg="computed size is not the good one")
def test_invariants(self): m = SASModel() m.read(self.testfile1) f_np, r_np, d_np = m.calc_invariants(False) f_cy, r_cy, d_cy = m.calc_invariants(True) self.assertAlmostEqual(f_np, f_cy, 10, "fineness is the same %s!=%s" % (f_np, f_cy)) self.assertAlmostEqual(r_np, r_cy, 10, "Rg is the same %s!=%s" % (r_np, r_cy)) self.assertAlmostEqual(d_np, d_cy, 10, "Dmax is the same %s!=%s" % (d_np, d_cy))
def assign_models(self, molecule=None): """ Create SASModels from pdb files saved in self.inputfiles and saved them in self.models. Center of mass, inertia tensor and canonical parameters are computed for each SASModel. :param molecule: optional 2d array, coordinates of the atoms for the model to create :return self.models: list of SASModel """ if not self.inputfiles and len(molecule) == 0: logger.error("No input files") if self.inputfiles: for inputpdb in self.inputfiles: model = SASModel() model.read(inputpdb) model.centroid() model.inertiatensor() model.canonical_parameters() self.sasmodels.append(model) if len(self.inputfiles) != len(self.sasmodels): logger.error("Problem of assignment\n%s models for %s files" % (len(self.sasmodels), len(self.inputfiles))) elif len(molecule) != 0: model = SASModel() model.atoms = molecule model.centroid() model.inertiatensor() model.canonical_parameters() self.sasmodels.append(model) return self.sasmodels
def test_dist(self): m = assign_random_mol() n = SASModel(m.atoms) distance = m.dist(n, m.atoms, n.atoms) self.assertEqual(distance, 0, msg="NSD different of 0: %s!=0" % (distance))
def test_rfactor(self): m = SASModel() m.read(self.testfile) n = SASModel() n.read(self.testfile) self.assertEqual(m.rfactor, n.rfactor, msg="R-factor is not the same %s != %s"%(m.rfactor, n.rfactor))