def test_Write_6(self):
     
     if not haveStride: return
     from MolKit import Read
     self.mol = Read("Data/1crn.pdb")[0]
     self.mol.secondaryStructureFromStride()
     from MolKit.pdbWriter import PdbWriter
     writer = PdbWriter()
     writer.write('Data/1crn_writer.pdb', self.mol,
                  records=['ATOM', 'HETATM', 'CONECT',
                           'TURN','HELIX', 'SHEET'],
                  bondOrigin='all', ssOrigin='Stride')
     # Make sure that the ss information has been written out
     # properly.
     nmol = Read("Data/1crn_writer.pdb")[0]
     nmol.secondaryStructureFromFile()
     nsset = nmol.chains[0].secondarystructureset
     osset = self.mol.chains[0].secondarystructureset
     self.assertEqual(len(nsset), len(osset))
     for nss, oss in map(None, nsset, osset):
         self.assertEqual(nss.name, oss.name)
         self.assertEqual(nss.start.name,oss.start.name)
         self.assertEqual(nss.end.name, oss.end.name)
         self.assertEqual(len(nss.residues), len(oss.residues))
     os.system("rm Data/1crn_writer.pdb")
Exemple #2
0
 def __init__(self, filename):
     self.input_file = Read(filename)[0]
     self.output = filename.split('.')[0] + '.pdb'
     writer = PdbWriter()
     writer.write(self.output,
                  self.input_file.allAtoms,
                  records=['ATOM', 'HETATM'])
Exemple #3
0
    def __init__(self, original_pdb, pqr_file, metal):
        self.ori_pdb = Read(original_pdb)[0]
        self.pqr = Read(pqr_file)[0]
        self.metal = metal
        self.new_pdb = pqr_file.split('.')[0] + '.pdb'

        if self.metal:
            zn = self.ori_pdb.allAtoms.get(lambda x: x.element == 'Zn')
            # remove hydrogens added to HYS residues near ZN atoms
            close_atoms = self.pqr.closerThan(zn[0].coords, self.pqr.allAtoms,
                                              2.3)
            # FIXME: only take the first atoms in list
            for a in close_atoms:
                if a.element == 'H':
                    # print a.name
                    for b in a.bonds:
                        at2 = b.atom1
                        if at2 == a: at2 = b.atom2
                        at2.bonds.remove(b)
                        a.bonds.remove(b)
                    a.parent.remove(a)
                    del a
            self.pqr.allAtoms = self.pqr.chains.residues.atoms + zn
        writer = PdbWriter()
        writer.write(self.new_pdb,
                     self.pqr.allAtoms,
                     records=['ATOM', 'HETATM'])
Exemple #4
0
def write_pdb(pdbqt_parser, outfile):
  mol = pdbqt_parser[0]
  mol.buildBondsByDistance()
  mol.allAtoms.number = range(1, len(mol.allAtoms) + 1)
  
  writer = PdbWriter()
  writer.write(outfile, mol.allAtoms, records=['HETATM'], sort=1, bondOrigin=0)
Exemple #5
0
    def __init__(self, original_pdb, pqr_file, metals):
        self.ori_pdb = Read(original_pdb)[0]
        self.pqr = Read(pqr_file)[0]
        self.metals = metals
        self.new_pdb = pqr_file.split('.')[0] + '.pdb'

        uniq_list = {} # to avoid redundancy
        if self.metals:
            for met in self.metals:
                ele = met[1][:3].strip().lower()
                if ele not in uniq_list.keys():
                    uniq_list[ele] = met[2]
                else:
                    continue
            met_atoms = self.ori_pdb.allAtoms.get(lambda x: x.element.lower() in uniq_list)
            for atm in met_atoms:
                atm.charge = uniq_list[atm.element.lower()]
                print 'atoms charge', atm.element, uniq_list[atm.element.lower()]
            for met_atm in met_atoms:
                close_atoms = self.pqr.closerThan(met_atm.coords, self.pqr.allAtoms, 2.8)
            for a in close_atoms:
                if a.element == 'H':
                    for b in a.bonds:
                        at2 = b.atom1
                        if at2 == a: at2 = b.atom2
                        at2.bonds.remove(b)
                        a.bonds.remove(b)
                    a.parent.remove(a)
                    del a
                self.pqr.allAtoms = self.pqr.chains.residues.atoms
            self.pqr.allAtoms = self.pqr.chains.residues.atoms + met_atoms
        writer = PdbWriter()
        writer.write(self.new_pdb, self.pqr.allAtoms, records=['ATOM', 'HETATM'])
 def test_write(self):
     """
     test writing a pdb file
     """
     writer = PdbWriter()
     writer.write('test_pdbWriter.pdb', self.mol, bondOrigin=('File',))
     ans, errors = self.compare('Data/1crn.pdb', 'test_pdbWriter.pdb') 
     self.assertEquals(errors, None)
     self.assertEquals(ans, True)
def buildPdb(map_dict,
             npts,
             name='DlgBuilt',
             ctr=0,
             outputfile='results.pdb',
             scale=1.0):
    if debug: print "in buildPdb: tolerance=", tolerance
    name = 'DlgBuilt'
    mol = Protein(name=name)
    mol.curChain = Chain()
    mol.chains = ChainSet([mol.curChain])
    mol.curRes = Residue()
    mol.curChain.adopt(mol.curRes)
    mol.allAtoms = AtomSet()
    mol.curRes.atoms = mol.allAtoms
    nzpts = nypts = nxpts = npts
    #nxpts, nypts, nzpts = npts
    ctr = 0
    for ADtype, m in map_dict.items():
        if debug:
            print "PROCESSING ", ADtype, " array:", max(m.ravel()), ':', min(
                m.ravel())
        vals = []
        tctr = 0  #for number of each type
        for z in range(nzpts):
            for y in range(nypts):
                for x in range(nxpts):
                    val = scale * abs(m[x, y, z])
                    vals.append(val)
                    #if abs(val)>.005:
                    if val > tolerance * scale:
                        ctr += 1
                        name = ADtype + str(ctr)
                        #version3:
                        #info_lo = (xcen - numxcells*spacing,
                        #    ycen - numycells*spacing,
                        #    zcen - numzcells *spacing)
                        #using lower back pt of cube, i think
                        #xcoord = (x-info_lo[0])/spacing
                        #ycoord = (y-info_lo[1])/spacing
                        #zcoord = (z-info_lo[2])/spacing
                        #version2:
                        xcoord = (x - numxcells) * spacing + xcen
                        ycoord = (y - numycells) * spacing + ycen
                        zcoord = (z - numzcells) * spacing + zcen
                        coords = (xcoord, ycoord, zcoord)
                        tctr += 1
                        #    #print "addAtom: name=",name,"ADtype=", ADtype," val=", val, "coords=", coords,"ctr=", ctr
                        addAtom(mol, name, ADtype, val, coords, ctr)
        print "added ", tctr, '<-', ADtype, " atoms"
        if debug:
            print ADtype, ':', tctr, ' ', ctr
    print "total atoms=", ctr
    writer = PdbWriter()
    writer.write(outputfile, mol.allAtoms, records=['ATOM'])
 def test_write_2(self):
     """
     Tests that PdbWriter can write molecule parsed by MMCIFParser
     """
     # read a molecule
     parser = MMCIFParser(filename='Data/1CRN.cif')
     mol = parser.parse()
     # instanciate a PdbWriter and call the write method with the
     # default arguments
     from MolKit.pdbWriter import PdbWriter
     writer = PdbWriter()
     writer.write('Data/1crn_mmcifwriter.pdb', mol)
     os.remove('Data/1crn_mmcifwriter.pdb')
Exemple #9
0
 def get_ligand(self, sel, filename):
     selection = sel.split(':')
     new_mol = None
     for chain in self.mol.chains:
         for res in chain.residues:
             # exclude water residues
             if res.name[:3] in ['WAT', 'HOH', 'SOL', ' ZN']:
                 continue
             if selection == [chain.name, res.name[:3], res.name[3:]]:
                 new_mol = makeMoleculeFromAtoms('ligand', res.atoms)
                 writer = PdbWriter()
                 writer.write(filename, new_mol.allAtoms, records=['ATOM', 'HETATM'])
     return new_mol
 def test_write_2(self):
     """
     Tests that PdbWriter can write molecule parsed by MMCIFParser
     """
     # read a molecule
     parser = MMCIFParser(filename='Data/1CRN.cif')
     mol = parser.parse()
     # instanciate a PdbWriter and call the write method with the
     # default arguments
     from MolKit.pdbWriter import PdbWriter
     writer = PdbWriter()
     writer.write('Data/1crn_mmcifwriter.pdb', mol)
     os.remove('Data/1crn_mmcifwriter.pdb')
def buildPdb(map_dict, npts, name='DlgBuilt', ctr=0, outputfile='results.pdb', 
                    scale=1.0):
    if debug: print "in buildPdb: tolerance=", tolerance
    name = 'DlgBuilt'
    mol = Protein(name=name)
    mol.curChain = Chain()
    mol.chains = ChainSet([mol.curChain])
    mol.curRes = Residue()
    mol.curChain.adopt(mol.curRes)
    mol.allAtoms = AtomSet()
    mol.curRes.atoms = mol.allAtoms
    nzpts=nypts=nxpts = npts
    #nxpts, nypts, nzpts = npts
    ctr = 0
    for ADtype, m in map_dict.items():
        if debug: 
            print "PROCESSING ", ADtype, " array:", max(m.ravel()), ':', min(m.ravel())
        vals = []
        tctr = 0  #for number of each type
        for z in range(nzpts):
            for y in range(nypts):
                for x in range(nxpts):
                    val = scale * abs(m[x,y,z])
                    vals.append(val)
                    #if abs(val)>.005:
                    if val>tolerance*scale:
                        ctr += 1
                        name = ADtype + str(ctr)
                        #version3:
                        #info_lo = (xcen - numxcells*spacing,
                        #    ycen - numycells*spacing, 
                        #    zcen - numzcells *spacing)
                        #using lower back pt of cube, i think
                        #xcoord = (x-info_lo[0])/spacing
                        #ycoord = (y-info_lo[1])/spacing
                        #zcoord = (z-info_lo[2])/spacing
                        #version2:
                        xcoord = (x-numxcells)*spacing + xcen
                        ycoord = (y-numycells)*spacing + ycen
                        zcoord = (z-numzcells)*spacing + zcen
                        coords = (xcoord,ycoord,zcoord)
                        tctr += 1
                    #    #print "addAtom: name=",name,"ADtype=", ADtype," val=", val, "coords=", coords,"ctr=", ctr
                        addAtom(mol, name, ADtype, val, coords, ctr)
        print "added ",tctr, '<-', ADtype, " atoms"
        if debug:
            print ADtype, ':', tctr , ' ', ctr
    print "total atoms=", ctr
    writer = PdbWriter()
    writer.write(outputfile, mol.allAtoms, records=['ATOM'])
 def test_Write_2(self):
     """
     Test writing out CONECT records for the bonds described in
     the pdb file and built by distance.
     """
     from MolKit import Read
     self.mol = Read("Data/1crn.pdb")[0]
     self.mol.buildBondsByDistance()
     # instanciate a PdbWriter and call the write method with the
     # default arguments
     from MolKit.pdbWriter import PdbWriter
     writer = PdbWriter()
     writer.write('Data/1crn_writer.pdb', self.mol)
     from MolKit.pdbParser import PdbParser
     nmol = Read("Data/1crn_writer.pdb")[0]
     os.system("rm Data/1crn_writer.pdb")
    def test_Write_1(self):
        """
        Test the default option of the write method of a PdbWriter.
        Just write the ATOM, HETATM and CONECT records and bondOrigin
        is File.
        """
        # read a molecule
        from MolKit import Read
        self.mol = Read("Data/1crn.pdb")[0]

        # instanciate a PdbWriter and call the write method with the
        # default arguments
        from MolKit.pdbWriter import PdbWriter
        writer = PdbWriter()
        writer.write('Data/1crn_writer.pdb', self.mol)
        # This should write only the ATOM and CONECT records
        # The TER records are automatically created with the ATOM records

        # 1- Make sure that the file has been created
        import os
        self.failUnless(os.path.exists('Data/1crn_writer.pdb'))
        # 2- Make sure that the file created the proper records
        # Get the default records from the new pdb files
        from MolKit.pdbParser import PdbParser
        nmol = Read("Data/1crn_writer.pdb")[0]

        # COMPARE 
        ncoords = nmol.allAtoms.coords
        ocoords = self.mol.allAtoms.coords
        self.assertEqual(ncoords, ocoords)

        nname = nmol.allAtoms.name
        oname = nmol.allAtoms.name
        self.assertEqual(nname, oname)

        nbonds = nmol.allAtoms.bonds[0]
        obonds = self.mol.allAtoms.bonds[0]
        self.assertEqual(len(nbonds), len(obonds))
        nbatms = nbonds.atom1+nbonds.atom2
        nbatms = nbatms.uniq()
        nbatms.sort()
        
        nbatms = nbonds.atom1+nbonds.atom2
        nbatms = nbatms.uniq()
        nbatms.sort()
        os.system("rm Data/1crn_writer.pdb")
    def test_Write_4(self):
        """
        Test writing out the ATOM records and the CONECT records
        without the HETATM
        """
        from MolKit import Read
        self.mol = Read("Data/1bsr.pdb")[0]
        # instanciate a PdbWriter and call the write method with the
        # default arguments
        from MolKit.pdbWriter import PdbWriter
        writer = PdbWriter()
        writer.write('Data/1bsr_writer.pdb', self.mol,
                     records=['ATOM', 'CONECT'], bondOrigin=('File',))
        nmol = Read("Data/1bsr_writer.pdb")[0]

        nhoh = nmol.chains.residues.get(lambda x: x.type=="HOH")
        ohoh = self.mol.chains.residues.get(lambda x: x.type=="HOH")
        self.failUnless(len(nhoh)==0)
        os.system("rm Data/1bsr_writer.pdb")
 def test_Write_4Char_AtomNames(self):
     """ check that atoms with names of 4+char are written properly"""
     from MolKit import Read
     self.mol = Read("Data/HTet.mol2")[0]
     from MolKit.pdbWriter import PdbWriter
     writer = PdbWriter()
     writer.write('Data/test_HTet.pdb', self.mol)
     testmol = Read("Data/test_HTet.pdb")[0]
     self.assertEqual(len(self.mol.allAtoms), len(testmol.allAtoms))
     #check the 4char atoms have correct element types
     self.assertEqual(testmol.allAtoms[0].element, 'C')
     self.assertEqual(testmol.allAtoms[1].element, 'Cl')
     self.assertEqual(testmol.allAtoms[22].element, 'N')
     self.assertEqual(testmol.allAtoms[23].element, 'H')
     #check the 4char atoms have reasonable names
     self.assertEqual(testmol.allAtoms[0].name, 'C11')
     self.assertEqual(testmol.allAtoms[1].name, 'Cl22')
     self.assertEqual(testmol.allAtoms[22].name, 'N61')
     self.assertEqual(testmol.allAtoms[23].name, 'HN61')
     os.system("rm Data/test_HTet.pdb")
Exemple #16
0
    def writeCoords(self,score=None,filename1=None,filename2=None,
                    sort=True, transformed=False,
                    pdbRec=['ATOM', 'HETATM', 'CONECT'],
                    bondOrigin='all', ssOrigin=None):
        """ write the coords of the molecules in pdb file
        pdb is file will have the molecule name follow by number of conformation
        """
        writer = PdbWriter()
        if score is None:
            score = min( self.confcoords.keys())
        if not self.confcoords.has_key(float(score)): return

        c1 = self.confcoords[score][0]
        c2 = self.confcoords[score][1]

        if filename1 is None:
            filename1 = self.mol1.name + '_1.pdb'
        prev_conf = self.setCoords(self.atomset1,c1)
        
        writer.write(filename1, self.atomset1, sort=sort, records=pdbRec,
                     bondOrigin=bondOrigin, ssOrigin=ssOrigin)

        self.atomset1.setConformation(prev_conf)

        if filename2 is None:
            filename2 = self.mol2.name + '_1.pdb'
            
        prev_conf = self.setCoords(self.atomset2,c2)
        writer.write(filename2, self.atomset2, sort=sort, records=pdbRec,
                     bondOrigin=bondOrigin, ssOrigin=ssOrigin)
        self.atomset2.setConformation(prev_conf)
Exemple #17
0
        usage()
        sys.exit()

    mol = Read(filename)[0]
    if verbose: print('read ', filename)
    filetype = os.path.splitext(os.path.basename(filename))[1]
    if verbose: print("filetype=", filetype)
    writer = None
    if filetype == '.pdbqt':
        writer = PdbqtWriter()
    elif filetype == '.pdbq':
        writer = PdbqWriter()
    elif filetype == '.pdbqs':
        writer = PdbqsWriter()
    elif filetype == '.pdb':
        writer = PdbWriter()
    else:
        print('Sorry! Unable to write this filetype->', filetype)

    center = numpy.add.reduce(mol.allAtoms.coords) / len(mol.allAtoms)
    crds = numpy.array(mol.allAtoms.coords)
    center = numpy.add.reduce(crds) / len(mol.allAtoms)
    crds = crds - center
    crds = crds.tolist()
    mol.allAtoms.updateCoords(crds)
    lenCoords = len(crds)
    #rotate the atoms here
    if axis is not None and angle is not None:
        rot = (float(angle) * 3.14159 / 180.) % (2 * numpy.pi)
        x = numpy.array([0., 0., 0.])
        y = numpy.array(list(map(float, axis.split(','))))
Exemple #18
0
            usage()
            sys.exit()


    if not pdbqt_filename:
        print 'pdbqt_to_pdb: pdbqt_filename must be specified.'
        usage()
        sys.exit()

    mols = Read(pdbqt_filename)
    if verbose: print 'read ', pdbqt_filename
    mol = mols[0]
    mol.buildBondsByDistance()
    #fix number for problem files with alternative positions
    mol.allAtoms.number = range(1, len(mol.allAtoms)+1)

    #pdb_filename = mol.name + '.pdb'
    writer = PdbWriter()
    writer.write(pdb_filename, mol.allAtoms, records=['ATOM', 'HETATM'])

    if verbose:
        print "wrote ", 'ctr', " atoms to", pdb_filename
    

# To execute this command type:
# pdbqt_to_pdb.py -f pdbqt_filename_stem [-o outputfilename] -v




Exemple #19
0
def WritePDB(filename, node):
    from MolKit.pdbWriter import PdbWriter
    writer = PdbWriter()
    writer.write(filename, node)
Exemple #20
0
 def save_pdb(self, filename):
     """ avoid errors when visualize entry protein in pdbqt format"""
     mol = Read(filename)[0]
     writer = PdbWriter()
     writer.write(self.pdb, mol.allAtoms, records=['ATOM', 'HETATM'])
Exemple #21
0
def WritePDB(filename,node):
    from MolKit.pdbWriter import PdbWriter
    writer = PdbWriter()
    writer.write(filename, node)
            usage()
            sys.exit()


    if not pdbqt_filename:
        print 'pdbqt_to_pdb: pdbqt_filename must be specified.'
        usage()
        sys.exit()

    mols = Read(pdbqt_filename)
    if verbose: print 'read ', pdbqt_filename
    mol = mols[0]
    mol.buildBondsByDistance()
    #fix number for problem files with alternative positions
    mol.allAtoms.number = range(1, len(mol.allAtoms)+1)

    #pdb_filename = mol.name + '.pdb'
    writer = PdbWriter()
    writer.write(pdb_filename, mol.allAtoms, records=['ATOM', 'HETATM'])

    if verbose:
        print "wrote ", ctr, " atoms to", pdb_filename
    

# To execute this command type:
# pdbqt_to_pdb.py -f pdbqt_filename_stem [-o outputfilename] -v




 def test_constructor(self):
     """
     instantiate an PdbWriter
     """
     writer = PdbWriter()
     self.assertEquals(writer.__class__, PdbWriter)