Esempio n. 1
0
def randomSample():
    root = 'golden.dat'
    if not os.path.exists(root): os.mkdir(root)

    def mol2mol_init(ele):
        mol = [[i, 0.0, 0.0, 0.0] for i in ele]
        return mol

    size = 200
    folder_id = 0
    file_count = 0
    confs = calculator.grid._iter_conf()
    confs = list(confs)
    if len(confs) > 2000:
        confs = sample(list(confs), 2000)
    for idx, coors in calculator.gen_PDB(confs):
        #for id, coors in calculator.gen_atomic_coors(0,10):
        #print(idx, coors)

        if file_count % size == 0:
            folder = os.path.join(root, "EFT_%04d" % (folder_id))
            if not os.path.exists(folder): os.mkdir(folder)
            folder_id += 1
        pdb = open("%s/eft.%s.pdb" % (folder, idx), "w")
        pdb.write(coors)
        pdb.close()
        file_count += 1
def addHydrogensAndBonds(proteinpdbal):
    """ takes atom list, writes pdb
    runs tleap to add hydrogens and bonds
    I order the atoms in the individual residues, because tleap uses oreder that does not work with scream
    """
    f = tempfile.NamedTemporaryFile(mode='w', prefix='tmpAmber', dir='.')
    f.close()
    filename = f.name
    al = proteinpdbal
    for a in al:
        if a.aTag != 'ATOM  ':
            print 'Warning: addHydrogensAndBonds: will run TLEAP with HETATM entries, so not sure what will happen'
            break
    pdb.write(filename + '.pdb', al, withConect=False)
    with open(filename + '.tleap', 'w') as f:
        f.write('source leaprc.ff99SB \n')
        f.write('logFile %s.log \n' % filename)
        f.write('pdb = loadpdb %s.pdb \n' % filename)
        f.write('saveamberparm pdb %s.prmtop %s.inpcrd \n' %
                (filename, filename))
        f.write('quit \n')
    subprocess.call(['tleap', '-f', filename + '.tleap'])
    # check if wrong atoms have been added
    lines = open(filename + '.log').readlines()
    for line in lines:
        if line[0:5] == 'FATAL':
            sys.exit(
                'Error: fatal error in tleap (probably there are some unknown or extra atoms in the pdb)'
            )
        elif line[0:7] == '  Added':
            a = line.split()[-2].split('<')[-1]
            if a != 'OXT':
                print 'Warning: addHydrogensAndBonds: tleap added more heavy atoms than just OXT: %s in %s ' % (
                    a, ' '.join(line.split()[4:]))
    # read the amber files
    al2 = readTopoCord(filename + '.prmtop', filename + '.inpcrd')
    rl = residues.makeList(al)
    rl2 = residues.makeList(al2)
    if len(rl) != len(rl2):
        sys.exit(
            'Error: addHydrogensAndBonds: the file from tleap has different number of residues %d than the original file %d'
            % (len(rl2), len(rl)))
    for i, r in enumerate(rl):
        rl2[i].chain = r.chain
        rl2[i].rNo = r.rNo
        rl2[i].updateAtoms()
        rl2[i].sort()
    al2 = residues.makeAtomList(rl2)
    for a in al2:
        a.aTag = 'ATOM  '

    # clean up
    os.remove(filename + '.prmtop')
    os.remove(filename + '.inpcrd')
    os.remove(filename + '.tleap')
    os.remove(filename + '.pdb')
    os.remove(filename + '.log')
    os.remove('leap.log')
    return al2
Esempio n. 3
0
 def phase1(self):
     ti1=time.clock()
     print "Optimizing water positions"
     self.optimize()
     print "Optimizing organic positions"
     self.optimize2()
     ti2=time.clock()
     print ti2-ti1
     print "Preprocessing organic molecules."
     self.phase2()
     for pdb in self.pdbs:
         pdb.write(self.stamp,1)
Esempio n. 4
0
 def phase1(self):
     ti1 = time.clock()
     print "Optimizing water positions"
     self.optimize()
     print "Optimizing organic positions"
     self.optimize2()
     ti2 = time.clock()
     print ti2 - ti1
     print "Preprocessing organic molecules."
     self.phase2()
     for pdb in self.pdbs:
         pdb.write(self.stamp, 1)
Esempio n. 5
0
 def phase1(self,myid=0):
     ti1=time.clock()
     print "Optimizing water positions"
     self.optimize()
     #print "Optimizing organic positions"
     #self.optimize2()
     """
     sym=symgen.symgen()
     print "Preprocessing water molecules."
     for w in self.waters:
         w['chain']='W'
         symm=sym.varpass(w)
         flagger=0
         for j in symm:
             for i in j:
                 if(len(w.pdb.findneighbor(i,w['res num']))>0):
                     #print "SYMMETRY"
                     flagger+=1
                     t0 = "ATOM    957  O   HOH B   1      36.504 -10.582  -2.929  1.00 13.36      A    O"
                     t1 = w['res num']
                     t2 = w.pdb
                     temp = Atom(t0, t1, t2)
                     temp['x'] = i[0]
                     temp['y'] = i[1]
                     temp['z'] = i[2]
                     temp['res num']=w['res num']
                     #temp['B']=float("%.2d"%flagger)
                     temp['chain']='S'
                     w.pdb.append(temp)
     """
     ti2=time.clock()
     print ti2-ti1
     print "Preprocessing organic molecules."
     self.phase2()
     for pdb in self.pdbs:
         pdb.write(self.stamp,999,int(myid))
     os.chdir('../../../results/%d'%int(myid))
     filenames= os.listdir(os.getcwd())
     zf = zipfile.ZipFile('results.zip', 'w', zipfile.ZIP_DEFLATED)
     for f in filenames:
         zf.write(f)
         os.system('rm -rf %s'%f)
     zf.close()
     return
Esempio n. 6
0
def typeBondShell(al):
    '''runs on shell
    this assignes bond order to atom list using openbabel
    first pdb is created
    then it is read by python openbabel (pybel)
    then it is written into bgf
    then only the bond orders from the new bgf are used
    '''
    import os
    from pyvasek import mol2

    pdb.write('tempMol.pdb', al)
    os.system('babel ---errorlevel 2 -ipdb tempMol.pdb -omol2 tempMol.mol2')
    al2 = mol2.read('tempMol.mol2')
    #
    atoms.sortBondsLists(al)
    atoms.sortBondsLists(al2)
    for i in range(len(al)):
        a1 = al[i]
        a2 = al2[i]
        a1.order = a2.order[:]
Esempio n. 7
0
 def phase1(self):
     ti1 = time.clock()
     print "Optimizing water positions"
     self.optimize()
     #print "Optimizing organic positions"
     #self.optimize2()
     """
     sym=symgen.symgen()
     print "Preprocessing water molecules."
     for w in self.waters:
         w['chain']='W'
         symm=sym.varpass(w)
         flagger=0
         for j in symm:
             for i in j:
                 if(len(w.pdb.findneighbor(i,w['res num']))>0):
                     #print "SYMMETRY"
                     flagger+=1
                     t0 = "ATOM    957  O   HOH B   1      36.504 -10.582  -2.929  1.00 13.36      A    O"
                     t1 = w['res num']
                     t2 = w.pdb
                     temp = Atom(t0, t1, t2)
                     temp['x'] = i[0]
                     temp['y'] = i[1]
                     temp['z'] = i[2]
                     temp['res num']=w['res num']
                     #temp['B']=float("%.2d"%flagger)
                     temp['chain']='S'
                     w.pdb.append(temp)
     """
     ti2 = time.clock()
     print ti2 - ti1
     print "Preprocessing organic molecules."
     self.phase2()
     for pdb in self.pdbs:
         pdb.write(self.stamp, 1)
Esempio n. 8
0
 def phase1(self):
     ti1=time.clock()
     print "Optimizing water positions"
     self.optimize()
     #print "Optimizing organic positions"
     #self.optimize2()
     """
     sym=symgen.symgen()
     print "Preprocessing water molecules."
     for w in self.waters:
         w['chain']='W'
         symm=sym.varpass(w)
         flagger=0
         for j in symm:
             for i in j:
                 if(len(w.pdb.findneighbor(i,w['res num']))>0):
                     #print "SYMMETRY"
                     flagger+=1
                     t0 = "ATOM    957  O   HOH B   1      36.504 -10.582  -2.929  1.00 13.36      A    O"
                     t1 = w['res num']
                     t2 = w.pdb
                     temp = Atom(t0, t1, t2)
                     temp['x'] = i[0]
                     temp['y'] = i[1]
                     temp['z'] = i[2]
                     temp['res num']=w['res num']
                     #temp['B']=float("%.2d"%flagger)
                     temp['chain']='S'
                     w.pdb.append(temp)
     """
     ti2=time.clock()
     print ti2-ti1
     print "Preprocessing organic molecules."
     self.phase2()
     for pdb in self.pdbs:
         pdb.write(self.stamp,1)