コード例 #1
0
import numpy as np

if len(sys.argv) < 5:
    print( "USAGE:", sys.argv[0], "RESID1 CHAIN1 RESID2 CHAIN1 PDB_1 ...")

r1 = int( sys.argv[1] )
c1 = sys.argv[2]
r2 = int( sys.argv[3] )
c2 = sys.argv[4]
name = "CA"

for i in range( 5, len(sys.argv)):
    with open( sys.argv[i] ) as f:
        pos1 = []
        pos2 = [] 
        found1 = False
        found2 = False
        for l in f:
            if ("ATOM" in l or "HETATM" in l) and  pdb.chain(l) == c1 and pdb.resid(l) == r1 and pdb.atom_name(l) == name:
                pos1 = pdb.position(l)
                found1 = True
            elif  ("ATOM" in l or "HETATM" in l) and pdb.chain(l) == c2 and pdb.resid(l) == r2 and pdb.atom_name(l) == name:
                pos2 = pdb.position(l)
                found2 = True
            if found1 and found2:
                print( sys.argv[i], np.linalg.norm( pos1 - pos2 ) , end = ' ')
                found1 = False
                found2 = False
            if l[:4] == "pose":
                print( l.split()[-1] )
コード例 #2
0
ファイル: pdb_rotate.py プロジェクト: renedominik/toolbox
#!/usr/bin/python3

import numpy as np
import math, sys
import pdb_functions as pdb
import math_functions as m

if len(sys.argv) < 5:
    print("USAGE:", sys.argv[0], "PDB X Y Z ANGLE optional:CHAIN1...")
    exit(1)

axis = [float(x) for x in sys.argv[2:5]]
angle = float(sys.argv[5])

chains = []
if len(sys.argv) > 6:
    chains = sys.argv[6:]

with open(sys.argv[1]) as f:
    for l in f:
        l = l.strip()
        if l[:4] == "ATOM" and (len(chains) == 0 or pdb.chain(l) in chains):
            pos = np.dot(m.rotation_matrix(axis, angle), pdb.position(l))
            l = pdb.write_position(l, pos)
            print(l)
        else:
            print(l)

#np.dot(rotation_matrix(axis, theta), v)
コード例 #3
0
pdb_file = sys.argv[1]
mode = sys.argv[2]    # 'atom' or chain, e.g. 'A'
atom_id = int(sys.argv[3])
distance = float( sys.argv[4] )
atom_types = []
if len(sys.argv) > 5:
    atom_types = sys.argv[5:]

    
    
ref_pos = []
with open( pdb_file ) as r:
    for l in r:
        if ("ATOM" in l or "HETATM" in l) and ( ("at" in mode and atom_id == pdb.atom_id(l)) or (pdb.chain(l) == mode and atom_id == pdb.residue_id(l))) and "TIP3" not in l:
            ref_pos.append( pdb.position(l))
            print(l.strip())

print('\n',len(ref_pos), ' reference atoms found\n')

previous = -666

with open(pdb_file) as r:
    for l in r:
        if l[:4] == "ATOM"  and ( len(atom_types) == 0 or pdb.atom_name(l) in atom_types):

            if( previous != pdb.residue_id(l)):
                #print( pdb.single_letter( pdb.residue_name(l) ) , end='')
                previous = pdb.residue_id(l)
                
            pos = pdb.position(l)
コード例 #4
0
pose = sys.argv[1]
nr = int(sys.argv[2])
mins = [float(x) for x in sys.argv[3:6]]
maxs = [float(x) for x in sys.argv[6:]]

print(pose, nr, mins, maxs)

pid = pose.rfind(".")
head = pose[:pid]
tail = pose[pid + 1:]

pdb_lines = []
with open(pose) as f:
    pdb_lines = f.readlines()

cms = at.CMS(pose)

for i in range(0, nr):
    pos = [r.uniform(low, high) for low, high in zip(mins, maxs)]
    axis = [r.uniform(-1.0, 1.0) for j in range(0, 3)]
    angle = r.uniform(0, 2.0 * np.pi)
    matrix = m.rotation_matrix(axis, angle)
    filename = head + '_' + str(i) + '.' + tail
    print(filename)
    with open(filename, 'w') as w:
        for l in pdb_lines:
            if l[:4] == "ATOM":
                x = np.dot(matrix, pdb.position(l) - cms)
                l = pdb.write_position(l, x + pos)
            w.write(l)
コード例 #5
0
ファイル: pdb_pca.py プロジェクト: renedominik/toolbox
if len(sys.argv) < 2:
    print( "USAGE: ", sys.argv[0], "PDB (optional: CHAIN1 ..)")
    exit(1)

pos = []
chains = []
if len(sys.argv) > 2:
    chains = sys.argv[2:]


with open( sys.argv[1]) as f:
    for l in f:
        if l[:4] != "ATOM" or (len(chains)>0 and pdb.chain(l) not in chains):
            continue
        pos.append( pdb.position(l) ) 

pos = np.array( pos)
print( 'first pos:', pos[0])
print( pos.shape)

pca = PCA(n_components=3)
newpos = pca.fit(pos)

print( pca.components_)

print( pca.explained_variance_)

### test by hand implementation: ###
print( 'first pos:', pos[0])
コード例 #6
0
x1 = []
x2 = []
atoms = []

print sys.argv

with open( pdb_file ) as f:
    for l in f:
        if l[:4] != "ATOM" or l[21] != chain: continue

        l_atom_name = pdb.atom_name( l )
        l_resid = pdb.resid(l)

        # calpha collection
        if l_atom_name == atomname:
            p = pdb.position(l)
            if p[2] >= min_z and p[2] <= max_z:
                atoms.append( [ chain , l_resid , p ] )
                
        if l_resid != resid: continue

        if l_atom_name == atom_name_1:
            print l
            x1 = pdb.position(l)
        elif l_atom_name == atom_name_2:
            print l
            x2 = pdb.position(l)

sidechain = np.array(x2) - np.array(x1)

print len( atoms), atomname , "collected"
コード例 #7
0
ファイル: pdb_shift.py プロジェクト: renedominik/toolbox
if len(sys.argv) < 3:
    print "USAGE:", sys.argv[
        0], " FIRST.pdb XSHIFT YSHIFT ZSHIFT optional:CHAIN_1 (...)"
    print "move all or specified chains by x,y,z"
    print "bye"
    exit(1)

# to make this safe from HETATM section, use
#from Bio import Struct
#s = Struct.read('protein_A.pdb')
# p = s.as_protein()  # strip off hetatms

first_file = sys.argv[1]

shift = np.array([float(sys.argv[2]), float(sys.argv[3]), float(sys.argv[4])])

chains = []
if len(sys.argv) > 5:
    chains = sys.argv[5:]

with open(first_file) as f:
    for l in f:
        if len(l) > 50 and (l[0:4] == "ATOM" or l[0:6] == "HETATM") and (
                len(chains) == 0 or pdb.chain(l) in chains):
            pos = shift + pdb.position(l)
            l = pdb.write_position(l, pos)
            print l,
        else:
            print l,