Ejemplo n.º 1
0
def read_pdb(pdbin="undefined"):

    log_string = "\n  >> clipper_tools: io.molecules.read_pdb"
    log_string += "\n     pdbin: %s" % pdbin

    xml_root = etree.Element('input_file')
    xml_root.attrib['name'] = pdbin
    xml_root.attrib['type'] = 'PDB'

    if pdbin is not "undefined":

        f = clipper.MMDBfile()
        f.read_file(pdbin)
        mmol = clipper.MiniMol()
        f.import_minimol(mmol)

        log_string += "\n  << read_pdb has finished\n"
        xml_root.attrib['ok'] = 'yes'

        return log_string, xml_root, mmol

    else:
        log_string += "\n  ERROR: No input PDB was supplied"
        log_string += "\n  << read_pdb has finished \n"
        xml_root.attrib['ok'] = 'no'
        return log_string, xml_root, None
Ejemplo n.º 2
0
    def test_orth_frac(self, verbose=False):
        '''
        Test mateix methods of clipper-python bindings
        '''
        pdb_in_path = os.path.join(self.test_data_path, '1uoy.pdb')
        assert os.path.exists(pdb_in_path)
        # Set minimol
        f = clipper.MMDBfile()
        f.read_file(pdb_in_path)
        mmol = clipper.MiniMol()
        f.import_minimol(mmol)

        atoms = mmol.atom_list()

        cell = mmol.cell()
        frac_matrix = cell.matrix_frac()
        orth_matrix = cell.matrix_orth()

        self.assertAlmostEqual(orth_matrix[0][0], 43.615, places=3)
        self.assertAlmostEqual(orth_matrix[1][1], 58.436, places=3)
        self.assertAlmostEqual(orth_matrix[2][2], 53.415, places=3)
        self.assertAlmostEqual(frac_matrix[0][0], 0.02293, places=3)
        self.assertAlmostEqual(frac_matrix[1][1], 0.01711, places=3)
        self.assertAlmostEqual(frac_matrix[2][2], 0.01872, places=3)

        for at in atoms:
            c = at.coord_orth()
            cnew = orth_matrix * (frac_matrix * c)
            cdiff = cnew - c
            xdiff,ydiff,zdiff = cdiff.x(), cdiff.y(), cdiff.z()
            self.assertAlmostEqual(xdiff, 0.0, places=4)
            self.assertAlmostEqual(ydiff, 0.0, places=4)
            self.assertAlmostEqual(zdiff, 0.0, places=4)

        new_cell = clipper.Cell(clipper.Cell_descr(cell.a()+.2,cell.b(),cell.c(),cell.alpha(),cell.beta(),cell.gamma()))
        orth_matrix = new_cell.matrix_orth()

        self.assertAlmostEqual(orth_matrix[0][0], 43.815, places=3)
        self.assertAlmostEqual(orth_matrix[1][1], 58.436, places=3)
        self.assertAlmostEqual(orth_matrix[2][2], 53.415, places=3)
        for at in atoms:
            c = at.coord_orth()
            cnew = orth_matrix * (frac_matrix * c)
            cdiff = cnew - c
            xdiff,ydiff,zdiff = cdiff.x(), cdiff.y(), cdiff.z()
            self.assertTrue(abs(xdiff)<0.2)
            self.assertAlmostEqual(ydiff, 0.0, places=4)
            self.assertAlmostEqual(zdiff, 0.0, places=4)
Ejemplo n.º 3
0
def write_pdb(pdbout="xyzout.pdb", molout=None):

    log_string = "\n  >> clipper_tools: io.molecules.write_pdb"
    log_string += "\n     pdbout: %s" % pdbout

    xml_root = etree.Element('output_file')
    xml_root.attrib['name'] = pdbout
    xml_root.attrib['type'] = 'PDB'

    if molout is None:
        xml_root.attrib['ok'] = 'no'
        log_string += "\n  ERROR: No input MiniMol was supplied"
        log_string += "\n  << write_pdb has finished \n"
        return log_string, xml_root
    else:
        mmdb = clipper.MMDBfile()
        mmdb.export_minimol(molout)
        mmdb.write_file(pdbout, 0)
        log_string += "\n  << write_pdb has finished \n"
        xml_root.attrib['ok'] = 'yes'

    return log_string, xml_root
Ejemplo n.º 4
0
import clipper

f = clipper.MMDBfile()
f.read_file("test.pdb")
mmol = clipper.MiniMol()
print mmol
f.import_minimol(mmol)

f.write_file("silly.pdb", 0)
f.write_file("silly.cif", clipper.MMDBManager.CIF)

print dir(f)
print dir(mmol)

atoms = mmol.atom_list()

print dir(atoms)
print atoms[0].coord_orth().x()
print len(atoms)

for i in range(len(atoms)):
    print atoms[i]

for at in atoms:
    c = at.coord_orth()
    print c.x(), c.y(), c.z()

mod = mmol.model()

for poly in mod:
    for mono in poly:
Ejemplo n.º 5
0
    def test_minimol(self, verbose=False):
        '''
        Test minimol clipper-python bindings
        '''
        pdb_in_path = os.path.join(self.test_data_path, '1uoy.pdb')
        assert os.path.exists(pdb_in_path)
        # Set minimol
        f = clipper.MMDBfile()
        f.read_file(pdb_in_path)
        mmol = clipper.MiniMol()
        f.import_minimol(mmol)

        # Test PDB/cif i/o
        pdb_out_path = os.path.join(self.test_output, '1uoy_mm.pdb')
        cif_out_path = os.path.join(self.test_output, '1uoy_mm.cif')
        f.write_file(pdb_out_path, 0)
        assert os.path.exists(pdb_out_path)
        f.write_file(cif_out_path, clipper.MMDBManager.CIF)
        assert os.path.exists(cif_out_path)

        # What you get...
        if verbose:
            print(dir(f))
            print(dir(mmol))

        # Get atoms
        atoms = mmol.atom_list()
        if verbose:
            print(dir(atoms))
            print(atoms[0].coord_orth().x())
            print(len(atoms))

        # Loop through atoms
        self.assertEqual(len(atoms), 581)
        if verbose:
            for i in range(len(atoms)):
                print(atoms[i])

        # Get atom coords
        self.assertEqual(atoms[0].coord_orth().x(), -1.975)
        if verbose:
            for at in atoms:
                c = at.coord_orth()
                print(c.x(), c.y(), c.z())

        # Loop through model, chain, residue, atom
        mod = mmol.model()
        for poly in mod:
            for mono in poly:
                for atom in mono:
                    if verbose:
                        print(atom.coord_orth().x(),
                              atom.coord_orth().y(),
                              atom.coord_orth().z())

        # Access atom directly, set properties
        self.assertEqual(mmol[0][0][0].occupancy(), 1.0)
        mmol[0][0][0].set_occupancy(0.5)
        print(mmol[0][0][0].occupancy())
        self.assertEqual(mmol[0][0][0].occupancy(), 0.5)

        mmol[0][0][0].set_u_iso(10.0)
        print(mmol[0][0][0].u_iso())
        self.assertEqual(mmol[0][0][0].u_iso(), 10.0)