#!/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)
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] )
print( "NOTE: script is subject to continuos adjustment, check script before using it!!") 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)
from sklearn.decomposition import PCA import sys 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: ###
def SetResidueType(line, typ): typ = typ.strip() if len(typ) != 3: print "ERROR: residue type has to be given in three letter code:", typ exit(1) return line[:17] + typ + line[20:] chains = sys.argv[2:] if len(sys.argv) < 3: print "USAGE", sys.argv[0], "FILE.pdb CHAIN1 ..." exit(1) atoms = ["C", "N", "O", "CA"] with open(sys.argv[1]) as f: for l in f: l = l.strip() # whattodo with hatatoms? if l[:4] != "ATOM": print l continue found = False if pdb.chain(l) not in chains or pdb.atom_name(l) in atoms: print l
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,