## TEMPY is a Python library designed to help the user manipulate and analyse atomic structures and density maps from 3D EM.
## Copyright (c) 2013 Daven Vasishtan,Irene Farabella, Arun Prasad Pandurangan, Harpal Sahota, Frank Alber and Maya Topf
from numpy import ndarray,array,append
from math import *
from random import randrange
from os import system
from time import time
import urllib
import numpy
# -- Local imports -- #
from Vector import *
from EMMap import *
from ProtRep_Biopy import *
[docs]class EnsembleGeneration:
"""A class to create ensemble of structure instance"""
def __init__(self):
pass
[docs] def randomise_structs(self,struct, no_of_structs, max_trans, max_rot, v_grain=30, rad=False):
"""
Generate an ensemble of Structure Instance.
Arguments:
*struct*
Input Structure Instance
*no_of_structs*
int, number of structures to output
*max_trans*
Maximum translation permitted
*max_rot*
Maximum rotation permitted (in degree if rad=False)
*v_grain*
Graning Level for the generation of random vetors (default=30)
"""
ensemble_list=[]
for x in range(0,no_of_structs):
struct.randomise_position(max_trans, max_rot, v_grain, rad)
if write==True:
#print "model_num: ",(count+1),"angle: ",x,"tranls_increment: ",transl_x[count],transl_y[count],transl_z[count]
struct.write_to_PDB(file_name)
ensemble_list.append(struct.copy())
struct.reset_position()
else:
ensemble_list.append(struct.copy())
#print "model_num: ",(count+1),"angle: ",x,"tranls_increment: ",transl_x[count],transl_y[count],transl_z[count]
struct.reset_position()
return ensemble_list
[docs] def anglar_sweep(self,struct, axis, translation_vector, no_of_structs, loc_rotation_angle, output_template, atom_com_ind=False,write=False):
"""
Generate an ensemble of Structure Instance
NOTE - Chose the number of structures for the ensemble accordingly with the angular increment step (loc_rotation_angle/no_of_structs) and
translational increment step (translation_vector/no_of_structs) required.
Default setting is around the Center of Mass.
Arguments:
*struct*
Input Structure Instance
*axis*
3-ple, axis for translation
*translation_vector*
3-ple, vector for translation
*no_of_structs*
int, number of structures to output
*loc_rotation_angle*
tuple, rotation angle for local rotation (degrees)
*output_template*
string, prefix name for outputted pdb files
*atom_com_ind*
int, index of atom to rotate around. If False, rotates around centre of mass
*write*
True will write out each Structure Instance in the ensemble as single PDB.
"""
# Work out distance between adjacent structures
ensemble_list=[]
grain = loc_rotation_angle/no_of_structs
if int(grain)<1:
print "Warning: less then 1deg rotation"
else:
transl_x=numpy.linspace(0, translation_vector[0], num=no_of_structs)
transl_y=numpy.linspace(0, translation_vector[1], num=no_of_structs)
transl_z=numpy.linspace(0, translation_vector[2], num=no_of_structs)
angle_rot=numpy.linspace(0,loc_rotation_angle,num=no_of_structs)
count=-1
for x in angle_rot:
count+=1
file_name=output_template+str(count+1)+".pdb"
if atom_com_ind:
loc_point = struct[atom_com_ind].get_pos_vector()
struct.rotate_by_axis_angle(axis[0],axis[1],axis[2], x, com=loc_point)
else:
struct.rotate_by_axis_angle(axis[0],axis[1],axis[2],x)
struct.translate(transl_x[count],transl_y[count],transl_z[count])
if write==True:
#print "model_num: ",(count+1),"angle: ",x,"tranls_increment: ",transl_x[count],transl_y[count],transl_z[count]
struct.write_to_PDB(file_name)
ensemble_list.append(struct.copy())
else:
ensemble_list.append(struct.copy())
#print "model_num: ",(count+1),"angle: ",x,"tranls_increment: ",transl_x[count],transl_y[count],transl_z[count]
struct.reset_position()
return ensemble_list
[docs] def circular_sweep_with_fixed_spin(self,struct, axis, point, ang_range, no_of_structs, output_template, loc_axis=False, loc_ang_range=False, atom_com_ind=False,write=False):
"""
Generate an ensemble of Structure Instance
Arguments:
*struct*
Input Structure Instance
*axis*
3-ple, axis around which the large scale rotation will be done
*point*
3-ple, point around which large scale rotation will be done
*ang_range*
tuple, rotation range (degrees)
*no_of_structs*
int, number of structures to output
*output_template*
string, prefix name for outputted pdb files
*loc_axis*
3-ple, axis for local rotation around centre of mass
*loc_ang_range*
tuple, rotation range for local rotation (degrees)
*atom_com_ind*
int, index of atom to rotate around. If False, rotates around centre of mass.
*write*
True will write out each Structure Instance in the ensemble as single PDB.
"""
ensemble_list=[]
# Work out angle between adjacent structures
grain = (ang_range[1]-ang_range[0])/no_of_structs
# Make point into Vector object
point = Vector(point[0], point[1],point[2])
for r in range(no_of_structs):
# Rotation around defined point
self.rotate_by_axis_angle(axis[0],axis[1],axis[2], r*grain, com=point)
if loc_axis and loc_ang_range:
# Rotation around centre of mass or atom, if specified
loc_grain = (loc_ang_range[1]-loc_ang_range[0])/no_of_structs
if atom_com_ind:
loc_point = a[atom_com_ind].get_pos_vector()
self.rotate_by_axis_angle(loc_axis[0],loc_axis[1],loc_axis[2], r*loc_grain, com=loc_point)
else:
self.rotate_by_axis_angle(loc_axis[0],loc_axis[1],loc_axis[2], r*loc_grain)
if write==True:
#print "model_num: ",(count+1),"angle: ",x,"tranls_increment: ",transl_x[count],transl_y[count],transl_z[count]
struct.write_to_PDB(file_name)
ensemble_list.append(struct.copy())
else:
ensemble_list.append(struct.copy())
#print "model_num: ",(count+1),"angle: ",x,"tranls_increment: ",transl_x[count],transl_y[count],transl_z[count]
struct.reset_position()
return ensemble_list
[docs] def circular_sweep_with_tangential_spin(self,struct, axis, point, ang_range, no_of_structs, output_template, loc_ang_range=False, atom_com_ind=False,write=False):
"""
Generate an ensemble of Structure Instance
Arguments:
*struct*
Input Structure Instance
*axis*
3-ple, axis around which the large scale rotation will be done
*point*
3-ple, point around which large scale rotation will be done
*ang_range*
tuple, rotation range (degrees)
*no_of_structs*
int, number of structures to output
*output_template*
string, prefix name for outputted pdb files
*loc_ang_range*
tuple, rotation range for local rotation (degrees)
*atom_com_ind*
int, index of atom to rotate around. If False, rotates around centre of mass.
*write*
True will write out each Structure Instance in the ensemble as single PDB.
"""
ensemble_list=[]
# Work out angle between adjacent structures
grain = (ang_range[1]-ang_range[0])/no_of_structs
# Make point and axis into Vector objects
point = Vector(point[0], point[1],point[2])
axis = Vector(axis[0], axis[1], axis[2])
for r in range(no_of_structs):
# Rotation around defined point
self.rotate_by_axis_angle(axis[0],axis[1],axis[2], r*grain, com=point)
if loc_ang_range:
# Rotation around centre of mass or atom, if specified
loc_grain = (loc_ang_range[1]-loc_ang_range[0])/no_of_structs
if atom_com_ind:
loc_point = self[atom_com_ind].get_pos_vector()
else:
loc_point = self.CoM
# Axis of local spin is cross product of axis and radius of rotation (ie. the tangent of the circular arc being traversed)
rad = (loc_point-point).unit()
loc_axis = rad.cross(axis)
self.rotate_by_axis_angle(loc_axis[0],loc_axis[1],loc_axis[2], r*loc_grain)
if write==True:
#print "model_num: ",(count+1),"angle: ",x,"tranls_increment: ",transl_x[count],transl_y[count],transl_z[count]
struct.write_to_PDB(file_name)
ensemble_list.append(struct.copy())
else:
ensemble_list.append(struct.copy())
#print "model_num: ",(count+1),"angle: ",x,"tranls_increment: ",transl_x[count],transl_y[count],transl_z[count]
struct.reset_position()
return ensemble_list
[docs] def spiral_sweep(self, struct, axis, dist, no_of_structs, loc_ang_range, loc_axis, output_template, atom_com_ind=False,write=False):
"""
Generate an ensemble of Structure Instance
Arguments:
*struct*
Input Structure Instance
*axis*
3-ple, axis for translation
*dist*
int, translation range (Angstroms)
*no_of_structs*
int, number of structures to output
*loc_axis*
3-ple, axis for local rotation around centre of mass
*loc_ang_range*
tuple, rotation range for local rotation (degrees)
*output_template*
string, prefix name for outputted pdb files
*atom_com_ind*
int, index of atom to rotate around. If False, rotates around centre of mass.
*write*
True will write out each Structure Instance in the ensemble as single PDB.
"""
# Work out distance between adjacent structures
grain = dist/no_of_structs
# Make axis into vector of length 1
axis = Vector(axis[0], axis[1], axis[2]).unit()
for r in range(no_of_structs):
# Translate structure along axis
self.translate(axis.x*r*grain,axis.y*r*grain,axis.z*r*grain)
# Rotation around centre of mass
loc_grain = (loc_ang_range[1]-loc_ang_range[0])/no_of_structs
if atom_com_ind:
loc_point = self[atom_com_ind].get_pos_vector()
self.rotate_by_axis_angle(loc_axis[0],loc_axis[1],loc_axis[2], r*loc_grain, com=loc_point)
else:
self.rotate_by_axis_angle(loc_axis[0],loc_axis[1],loc_axis[2], r*loc_grain)
if write==True:
#print "model_num: ",(count+1),"angle: ",x,"tranls_increment: ",transl_x[count],transl_y[count],transl_z[count]
struct.write_to_PDB(file_name)
ensemble_list.append(struct.copy())
else:
ensemble_list.append(struct.copy())
#print "model_num: ",(count+1),"angle: ",x,"tranls_increment: ",transl_x[count],transl_y[count],transl_z[count]
struct.reset_position()
return ensemble_list