Пример #1
0
 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")
Пример #2
0
 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")
Пример #3
0
 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))
Пример #4
0
 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))
Пример #5
0
 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")
Пример #6
0
    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
Пример #7
0
 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)
Пример #8
0
 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")
Пример #9
0
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
Пример #10
0
    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
Пример #11
0
    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
Пример #12
0
 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")
Пример #13
0
    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
Пример #14
0
    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")
Пример #15
0
 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))
Пример #16
0
    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
Пример #17
0
    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
Пример #18
0
 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))
Пример #19
0
 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))