def test_cif(): for filename in ['files/cif_struct.cif', 'files/cif_cart_struct.cif']: p1 = CifFile(filename).get_struct() assert p1.cell is not None assert p1.cryst_const is not None assert p1.symbols is not None assert p1.coords is not None assert p1.coords_frac is not None # test writing filename = os.path.join(testdir, 'test_write_cif.cif') io.write_cif(filename, p1) p2 = CifFile(filename).get_struct() np.testing.assert_array_almost_equal(p1.coords_frac, p2.coords_frac) np.testing.assert_array_almost_equal(p1.coords, p2.coords) np.testing.assert_array_almost_equal(p1.cryst_const, p2.cryst_const) np.testing.assert_array_almost_equal(p1.cell, p2.cell) assert p1.symbols == p2.symbols
def test_cif_parse(): tools.skip_if_pkg_missing('CifFile') for filename in ['files/cif_struct.cif', 'files/cif_cart_struct.cif']: p1 = CifFile(filename).get_struct() assert p1.cell is not None assert p1.cryst_const is not None assert p1.symbols is not None assert p1.coords is not None assert p1.coords_frac is not None # test writing filename = os.path.join(testdir, 'test_write_cif.cif') io.write_cif(filename, p1) p2 = CifFile(filename).get_struct() np.testing.assert_array_almost_equal(p1.coords_frac, p2.coords_frac) np.testing.assert_array_almost_equal(p1.coords, p2.coords) np.testing.assert_array_almost_equal(p1.cryst_const, p2.cryst_const) np.testing.assert_array_almost_equal(p1.cell, p2.cell) assert p1.symbols == p2.symbols
#!/usr/bin/env python # Read badly formatted PDB file (i.e. generated by Gromacs' genbox tool) and # write to CIF file. Use this if openbabel doesn't do the job properly. It may # complain that columns 77-78 are empty and reads the atom symbols wrong. # pwtools.parse.PDBFile is more forgiving. import sys from pwtools import io def help(prog): print(""" usage ----- {} input.pdb [output.cif] """.format(prog)) if __name__ == '__main__': argv = sys.argv prog = argv[0] if (len(argv) not in [2,3]) or (argv[1] in ['-h', '--help']): help(prog) sys.exit() infile = argv[1] if len(argv) == 3: outfile = argv[2] else: outfile = infile + '.cif' io.write_cif(outfile, io.read_pdb(infile))
# Read badly formatted PDB file (i.e. generated by Gromacs' genbox tool) and # write to CIF file. Use this if openbabel doesn't do the job properly. It may # complain that columns 77-78 are empty and reads the atom symbols wrong. # pwtools.parse.PDBFile is more forgiving. import sys from pwtools import io def help(prog): print(""" usage ----- {} input.pdb [output.cif] """.format(prog)) if __name__ == '__main__': argv = sys.argv prog = argv[0] if (len(argv) not in [2, 3]) or (argv[1] in ['-h', '--help']): help(prog) sys.exit() infile = argv[1] if len(argv) == 3: outfile = argv[2] else: outfile = infile + '.cif' io.write_cif(outfile, io.read_pdb(infile))