Beispiel #1
0
def write_pdb(gaulog, scan_pts, opt_pts, args):

    # get the bytes
    chosen_bytes = []
    if scan_pts == 'all':
        for sbytes in gaulog.grep_bytes['orientation:']:
            if opt_pts == 'all':
                for byte in sbytes:
                    chosen_bytes.append(byte)  # this is crazy
            else:
                chosen_bytes.append(sbytes[opt_pts])
    else:
        sbytes = gaulog.grep_bytes['orientation:'][scan_pts]
        if opt_pts == 'all':
            for byte in sbytes:
                chosen_bytes.append(byte)  # this is reasonable
        else:
            chosen_bytes.append(sbytes[opt_pts])

    # produce txt output
    txt = ''
    txtf = {}
    model_number = 0
    for byte in chosen_bytes:
        model_number += 1
        xyz = gaulog.read_coordinates('all', byte)
        counter = 0
        txtd = {}
        txt += 'MODEL %d\n' % model_number
        for (coords, atom) in zip(xyz, gaulog.atoms_list):
            counter += 1  # consistent with gaussian line number
            atom.SetVector(coords[0], coords[1], coords[2])
            atom.set_pdbinfo(atoms.PDBinfo('ATOM', counter))
            if atom.oniom and args.files:
                layermask = (atom.oniom.layer, atom.oniom.mask)
                if layermask not in txtd:
                    txtd[layermask] = []
                txtd[layermask].append(iolines.atom2pdb(atom))
            elif atom.oniom and args.altloc:
                atom.pdbinfo.altloc = atom.oniom.layer
            txt += iolines.atom2pdb(atom)
        txt += 'ENDMDL\n'
        if model_number == 1:
            for layermask in txtd:
                txtf[layermask] = ''
        for layermask in txtd:
            txtf[layermask] += 'MODEL %d\n' % model_number
            for line in txtd[layermask]:
                txtf[layermask] += line
            txtf[layermask] += 'ENDMDL\n'
    return txt, txtf
Beispiel #2
0
def write_pdb(gaulog, scan_pts, opt_pts, args):

    # get the bytes
    chosen_bytes = []
    if scan_pts == 'all':
        for sbytes in gaulog.grep_bytes['orientation:']:
            if opt_pts == 'all':
                for byte in sbytes:
                    chosen_bytes.append(byte) # this is crazy
            else:
                chosen_bytes.append(sbytes[opt_pts])
    else:
        sbytes = gaulog.grep_bytes['orientation:'][scan_pts]
        if opt_pts == 'all':
            for byte in sbytes:
                chosen_bytes.append(byte) # this is reasonable 
        else:
            chosen_bytes.append(sbytes[opt_pts])

    # produce txt output
    txt = ''
    txtf = {}
    model_number = 0
    for byte in chosen_bytes:
        model_number += 1
        xyz = gaulog.read_coordinates('all', byte)
        counter = 0 
        txtd = {}
        txt += 'MODEL %d\n' % model_number
        for (coords, atom) in zip(xyz, gaulog.atoms_list):
            counter += 1 # consistent with gaussian line number
            atom.SetVector(coords[0],coords[1],coords[2])
            atom.set_pdbinfo(atoms.PDBinfo('ATOM', counter))
            if atom.oniom and args.files:
                layermask = (atom.oniom.layer, atom.oniom.mask)
                if layermask not in txtd:
                    txtd[layermask] = []
                txtd[layermask].append(iolines.atom2pdb(atom))
            elif atom.oniom and args.altloc:
                atom.pdbinfo.altloc = atom.oniom.layer
            txt += iolines.atom2pdb(atom)
        txt += 'ENDMDL\n'
        if model_number == 1:
            for layermask in txtd:
                txtf[layermask] = ''
        for layermask in txtd:
            txtf[layermask] += 'MODEL %d\n' % model_number
            for line in txtd[layermask]:
                txtf[layermask] += line
            txtf[layermask] += 'ENDMDL\n'
    return txt, txtf
Beispiel #3
0
def write_pdb(filename, atoms_list):
    with open(filename, 'w') as o:
        for (i, atom) in enumerate(atoms_list):
            o.write(iolines.atom2pdb(atom))
Beispiel #4
0
def main():

    args = get_args()

    # .com file ?
    if args.ext == '.com':
        gaucom = GAUCOM(args.gau)
        txt = ''
        txtf = {}
        for (i, at) in enumerate(gaucom.atoms_list):
            at.set_pdbinfo(atoms.PDBinfo('ATOM', i))
            if at.oniom and args.files:
                layermask = (at.oniom.layer, at.oniom.mask)
                if layermask not in txtf:
                    txtf[layermask] = ''
                txtf[layermask] += iolines.atom2pdb(at)
                if at.oniom.layer == 'H':
                    print at.x()
            if at.oniom and args.altloc:
                at.pdbinfo.altloc = at.oniom.layer
                txt += iolines.atom2pdb(at)
            else:
                txt += iolines.atom2pdb(at)

        if not args.files:
            with open(args.pdb, 'w') as o:
                o.write(txt)

        if args.files:
            for layermask in txtf:
                l, m = layermask
                with open('%s.%s.%d.pdb' % (args.base, l, m), 'w') as o:
                    o.write(txtf[layermask])

        return 0

    # Gaussian .log
    gaulog = GAULOG(args.gau)
    txt, txtf = write_pdb(gaulog, args.scan_step, args.opt_step, args)
    if not args.files:
        with open(args.pdb, 'w') as o:
            o.write(txt)
    else:
        for layermask in txtf:
            l, m = layermask
            with open('%s.%s.%d.pdb' % (args.base, l, m), 'w') as o:
                o.write(txtf[layermask])

    # Alignment Pymol
    if 'all' not in [args.scan_step, args.opt_step] or not args.align:
        return 0

    print('Aligning with pymol...')

    # MORE MAGIC: Use pymol for alignment
    o = args.pdb
    b = os.path.splitext(o)[0]
    txt = 'cmd.load("%s", format="pdb", multiplex=0)\n' % o
    txt += 'cmd.intra_fit("%s", state=0)\n' % b
    txt += 'cmd.save("%s", selection="%s", state=0, format="pdb")\n' % (o, b)
    txt += 'cmd.quit\n'
    with open('.temp_pymolscript.pml', "w") as temp_pymolscript:
        temp_pymolscript.write(txt)

    subprocess.call('pymol -qc .temp_pymolscript.pml', shell=True)
    subprocess.call('rm .temp_pymolscript.pml', shell=True)

    return 0
Beispiel #5
0
def main():
    
    args = get_args()

    # .com file ?
    if args.ext == '.com':
        gaucom = GAUCOM(args.gau)
        txt = ''
        txtf = {}
        for (i,at) in enumerate(gaucom.atoms_list):
            at.set_pdbinfo(atoms.PDBinfo('ATOM', i))
            txt += iolines.atom2pdb(at)
            if at.oniom and args.files:
                layermask = (at.oniom.layer, at.oniom.mask)
                if layermask not in txtf:
                    txtf[layermask] = ''
                txtf[layermask] += iolines.atom2pdb(at)
            if at.oniom and args.altloc:
                at.pdbinfo.altloc = at.oniom.layer
                txt += iolines.atom2pdb(at)

        if not args.files:
            with open(args.pdb, 'w') as o:
                o.write(txt)
            

        if args.files:
            for layermask in txtf:
                l, m = layermask
                with open('%s.%s.%d.pdb' % (args.base, l, m), 'w') as o:
                    o.write(txtf[layermask])
        
        return 0

    # Gaussian .log
    gaulog = GAULOG(args.gau)
    txt, txtf = write_pdb(gaulog, args.scan_step, args.opt_step, args)
    if not args.files:
        with open(args.pdb, 'w') as o:
            o.write(txt)
    else:
        for layermask in txtf:
            l, m = layermask
            with open('%s.%s.%d.pdb' % (args.base, l, m), 'w') as o:        
                o.write(txtf[layermask])

    # Alignment Pymol
    if 'all' not in [args.scan_step, args.opt_step] or not args.align:
        return 0

    print ('Aligning with pymol...')
    
    # MORE MAGIC: Use pymol for alignment
    o = args.pdb
    b = os.path.splitext(o)[0]
    txt  = 'cmd.load("%s", format="pdb", multiplex=0)\n' % o
    txt += 'cmd.intra_fit("%s", state=0)\n' % b
    txt += 'cmd.save("%s", selection="%s", state=0, format="pdb")\n' % (o, b)
    txt += 'cmd.quit\n'
    with open('.temp_pymolscript.pml', "w") as temp_pymolscript:
        temp_pymolscript.write(txt)

    subprocess.call('pymol -qc .temp_pymolscript.pml', shell=True)
    subprocess.call('rm .temp_pymolscript.pml', shell=True)
    
    return 0
def write_pdb(filename, atoms_list):
    with open(filename, 'w') as o:
        for (i, atom) in enumerate(atoms_list):
            o.write(iolines.atom2pdb(atom))
Beispiel #7
0
if str(scan_step) == 'all':
    print(len(gaussianlog.grep_bytes['orientation:']))
    #falta meter aqui a opcao opt_step =='all' , mas neste caso nao faz muito sentido
    #if opt_step == 'all':

    opt_step = int(opt_step)
    print(len(gaussianlog.grep_bytes['orientation:']))
    for i in range(len(gaussianlog.grep_bytes['orientation:'])):
        atoms_structure = gaussianlog.read_geometry(opt_step, i)
        for j,atom in enumerate(atoms_structure):
            pdb_obj = atoms.PDBinfo('ATOM', j+1 )              
            #res_obj = atoms.RESinfo(atom.element,'',0,'') #quando nao ha info pdb 
            #atom.set_resinfo(res_obj)
            atom.set_pdbinfo(pdb_obj)
            atom.pdbinfo.altloc = atom.oniom.layer
            open_output.write(iolines.atom2pdb(atom))
        open_output.write("END\n")

#casos em que so extraio de um scan
else:
    scan_step = int(scan_step)
    #todos os opt
    if opt_step == 'all':
        for i in range(len(gaussianlog.grep_bytes['orientation:'][scan_step])):
            atoms_structure = gaussianlog.read_geometry(i, scan_step)
            for j,atom in enumerate(atoms_structure):
                pdb_obj = atoms.PDBinfo('ATOM', j+1)
                atom.set_pdbinfo(pdb_obj)
                atom.pdbinfo.altloc = atom.oniom.layer
                open_output.write(iolines.atom2pdb(atom))
            open_output.write("END\n")