Esempio n. 1
0
    def rotate_by_euler(self,
                        x_turn,
                        y_turn,
                        z_turn,
                        x_trans=0,
                        y_trans=0,
                        z_trans=0,
                        rad=False,
                        com=False):
        """
        
        Rotate this Structure instance around its centre.
        
        Arguments:
            *x_turn,y_turn,z_turn*
                Euler angles (in radians if rad == True, else in degrees) used to rotate structure, in order XYZ.
            *x_trans, y_trans, z_trans*
                extra translational movement if required.
            *com*
                centre of mass around which to rotate the structure. If False, rotates around centre of mass of structure.
                
        """

        mat = Vector.euler_to_matrix(x_turn, y_turn, z_turn, rad)

        if not com:
            com = self.CoM.copy()

        newcom = com.matrix_transform(mat)
        offset = com - newcom
        self.matrix_transform(mat)
        self.translate(x_trans + offset.x, y_trans + offset.y,
                       z_trans + offset.z)
Esempio n. 2
0
 def get_pos_vector(self):
     """
     
     Return:
         Vector instance containing 3D coordinates of the atom.
     """
     return Vector.Vector(self.x, self.y, self.z)
Esempio n. 3
0
 def write_sasd_to_pdb(dens_map,sasds,pdb):
     """
         
     Outputs sasds to .pdb file
         
     Arguments:
        
        *dens_map*
            Solvent accessible surface on masked array
        *sasds*
            dictionary of sasds
        *pdb*
            .pdb file sasds were calculated on
     """
 
     if not os.path.exists('./Jwalk_results'):
         os.makedirs('./Jwalk_results')
 
     apix = dens_map.apix
     origin = dens_map.origin
     path_coord = {}
 
     for xl in sasds:
         a = []
         for (x,y,z) in sasds[xl]:
             a.append([(x*apix)+origin[0], (y*apix)+origin[1], (z*apix)+origin[2]])
         path_coord[xl] = a
 
     with open('./Jwalk_results/%s_crosslinks.pdb' % pdb[:-4],'w') as pdb:
 
         m_count = 1
         for xl in path_coord:
             (aa1,chain1,res1)=xl[0]
             (aa2,chain2,res2)=xl[1]
             sasd=xl[2]
             count = 1    
             pdb.write('MODEL %d %s%d%s-%s%d%s\n' % (m_count,res1,aa1,chain1,res2,aa2,chain2))
             m_count = m_count+1
             for (x,y,z) in path_coord[xl]:
                 p=Vector.Vector(x,y,z)
                 a=p.to_atom()
                 a.record_name = 'ATOM'
                 a.serial = count
                 a.atom_name = 'C'
                 a.alt_loc = ''
                 a.res = 'GLY'
                 a.chain = 'A'
                 a.res_no = count
                 a.icode = ''
                 a.occ = 1
                 a.temp_fac = 0
                 a.elem = 'C'
                 a.charge = ''
                 #print a.__dict__
                 #atom = BioPyAtom(a)
                 pdb.write(a.write_to_PDB())
                 count +=1
             pdb.write('END\n')
Esempio n. 4
0
    def randomise_position(self,
                           max_trans,
                           max_rot,
                           v_grain=30,
                           rad=False,
                           verbose=False):
        """
        
        Randomise the position of the Structure instance using random rotations and translations. 
                  
        Arguments:   
            *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)
        Return:
            Transformed position of Structure object
        """
        t_v = Vector.random_vector(-v_grain, v_grain).unit()
        r_v = Vector.random_vector(-v_grain, v_grain).unit()

        if max_trans <= 0:
            t_dist = 0
        else:
            t_dist = randrange(max_trans)

        if max_rot <= 0:
            r_ang = 0
        else:
            r_ang = randrange(max_rot)
        t_v = t_v.times(t_dist)
        self.rotate_by_axis_angle(r_v.x,
                                  r_v.y,
                                  r_v.z,
                                  r_ang,
                                  t_v.x,
                                  t_v.y,
                                  t_v.z,
                                  rad=rad)
        #self.translate(t_v.x, t_v.y, t_v.z)
        if verbose:
            print(r_v.x, r_v.y, r_v.z, r_ang, t_v.x, t_v.y, t_v.z)
        return (r_v.x, r_v.y, r_v.z, r_ang, t_v.x, t_v.y, t_v.z)
Esempio n. 5
0
    def spiral_sweep(self, structure_instance, axis, dist, no_of_structs, loc_ang_range, loc_axis, flag, atom_com_ind=False,write=False):
        """
        Generate an ensemble of Structure Instance
        
        Arguments:
            *structure_instance*
                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)
           *flag*
               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.
         Return:
            list of Structure Instance in which each item is [structure_instance_name,structure_instance]
               
        """
        ensemble_list=[]
        file_name0='mod_0'
        ensemble_list.append([file_name0,structure_instance])
        count=0
        # Work out distance between adjacent structures
        grain = dist/no_of_structs
        # Make axis into vector of length 1
        axis = Vector.Vector(axis[0], axis[1], axis[2]).unit()

        for r in range(no_of_structs):
            file_name=flag+str(r+1)+".pdb"
            # Translate structure along axis
            structure_instance.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()
                structure_instance.rotate_by_axis_angle(loc_axis[0],loc_axis[1],loc_axis[2], r*loc_grain, com=loc_point)
            else:
                structure_instance.rotate_by_axis_angle(loc_axis[0],loc_axis[1],loc_axis[2], r*loc_grain)

                if write==True:

                    structure_instance.write_to_PDB(file_name)
                    ensemble_list.append([file_name[:-4],structure_instance])
                else:
                    ensemble_list.append([file_name[:-4],structure_instance])
                structure_instance.reset_position()
        return ensemble_list
Esempio n. 6
0
 def get_torsion_angles(self):
     """
     
     Return:
         List of torsion angles in Structure instance.
     """
     vectorList = self.vectorise()
     angles = []
     for v in range(len(vectorList) - 2):
         angles.append(
             Vector.altTorsion(vectorList[v], vectorList[v + 1].reverse(),
                               vectorList[v + 2]))
     return angles
Esempio n. 7
0
 def calculate_centroid(self):
     """Return centre of mass of structure as a Vector instance."""
     x_Total = 0.0
     y_Total = 0.0
     z_Total = 0.0
     natom = 0.0
     for atom in self.atomList:
         x = atom.get_x()
         y = atom.get_y()
         z = atom.get_z()
         x_Total += x
         y_Total += y
         z_Total += z
         natom += 1
         x_CoM = x_Total / natom
         y_CoM = y_Total / natom
         z_CoM = z_Total / natom
     return Vector.Vector(x_CoM, y_CoM, z_CoM)
Esempio n. 8
0
    def __init__(self, ul_list, x, y, z):
        """
	
	Constructor to initialise the Vector gene.

	Arguments:
	    *ul_list*
	        A list containing the min and max translation allowed for the VectorGene.
	    *x*
	        x coordinate of a component.
	    *y*
	        y coordinate of a component.
	    *z*
	        z coordinate of a component.

	"""

        self.ul_list = ul_list
        self.x = x
        self.y = y
        self.z = z
        self.value = Vector(x, y, z)
Esempio n. 9
0
    def rotate_by_axis_angle(self,
                             x,
                             y,
                             z,
                             turn,
                             x_trans=0,
                             y_trans=0,
                             z_trans=0,
                             rad=False,
                             com=False):
        """
        
        Rotate the Structure instance around its centre.
        
        Arguments:
        
            *turn*
                angle (in radians if rad == True, else in degrees) to rotate map.
            *x,y,z*
                axis to rotate about, ie. x,y,z =  0,0,1 rotates the structure round the xy-plane.
            *x_trans, y_trans, z_trans*
                extra translational movement if required.
            *com*
                centre of mass around which to rotate the structure. If False, rotates around centre of mass of structure.
                
        """

        mat = Vector.axis_angle_to_matrix(x, y, z, turn, rad)

        if not com:
            com = self.CoM.copy()

        newcom = com.matrix_transform(mat)
        offset = com - newcom
        self.matrix_transform(mat)
        self.translate(x_trans + offset.x, y_trans + offset.y,
                       z_trans + offset.z)
Esempio n. 10
0
 def calculate_centre_of_mass(self):
     """
     
     Return:    
         Center of mass of structure as a Vector instance.
     
     """
     x_momentTotal = 0.0
     y_momentTotal = 0.0
     z_momentTotal = 0.0
     massTotal = 0.0
     for atom in self.atomList:
         x = atom.get_x()
         y = atom.get_y()
         z = atom.get_z()
         m = atom.get_mass()
         x_momentTotal += x * m
         y_momentTotal += y * m
         z_momentTotal += z * m
         massTotal += m
         x_CoM = x_momentTotal / massTotal
         y_CoM = y_momentTotal / massTotal
         z_CoM = z_momentTotal / massTotal
     return Vector.Vector(x_CoM, y_CoM, z_CoM)
Esempio n. 11
0
def VQ(D, n, epochs, alpha0=0.5, lam0=False):
    """ 
    
    Function to clusters a set of vectors (D) into a number (n) of codebook vectors

        Arguments:
            *n*
                number of VQ points to generate
            *epochs*
                number of iterations to run the algorithm
            *alpha0* 
                NOTE: Ask Daven regarding this parameter.
            *lam0* 
                NOTE: Ask Daven regarding this parameter.
    
    """

    if not lam0:
        lam0 = n / 2.

    dlen, dim = D.shape

    neurons = (np.random.rand(n, dim - 1) - 0.5) * 0.2
    train_len = epochs * dlen
    #random.seed(int(100*time()))

    den_sum = sum(D[:, 3])

    den_culm = []
    den_culm.append(D[0, 3])
    for i in range(1, dlen):
        den_culm.append(den_culm[i - 1] + D[i, 3])
    den_culm = np.matrix(den_culm)

    den_rand = den_sum * np.random.rand(train_len, 1)
    sample_inds = []
    for j in range(train_len):
        #if j%100000 == 0:
        #    print str(j)+' j'
        min_index = den_rand[j] < den_culm
        sample_inds.append(np.nonzero(min_index)[1][0, 0])
    lam = lam0 * (0.01 / lam0)**(np.arange(train_len) / float(train_len))
    alpha = alpha0 * (0.005 / alpha0)**(np.arange(train_len) /
                                        float(train_len))

    for i in range(train_len):
        #if i%5000 == 0:
        #    print i
        x = D[sample_inds[i], :3]
        x = np.array([int(y) for y in x])
        known = np.array([not math.isnan(y) for y in x])
        X = np.repeat([x], [n], axis=0)  #x[ones((n,1), dtype='i'), known]
        X = np.array(X[:, known], dtype='i')

        Dx = np.matrix(neurons[:, known] - X)
        inds = sorted(enumerate(np.power(Dx, 2) * np.matrix(known).T),
                      key=lambda t: t[1])
        inds = np.array([a[0] for a in inds])
        ranking = np.zeros(len(inds))
        ranking[inds] = range(n)

        h = map(math.exp, -ranking / lam[i])
        H = np.repeat([h], [len(known)], axis=0).T

        neurons = neurons + (alpha[i] * H) * (X - neurons[:, known])
    return [Vector(x[0], x[1], x[2]) for x in neurons]
Esempio n. 12
0
File: tempy.py Progetto: vtlim/GLIC
from TEMPy.StructureParser import PDBParser
from TEMPy.MapParser import MapParser
import numpy as np

# define point for rotation
# tempy examples use COM from input structure
# rotating against 0 0 0 doesn't seem to work
import TEMPy.Vector as Vector
com = Vector.Vector(90, 90, 90)

# read in map
target_map = MapParser.readMRC('GLIC_pH5_half1_unfil.mrc')  #read target map

# rotate along x, y, z
target_map = target_map.rotate_by_axis_angle(1, 0, 0,
                                             np.rad2deg(-3.1396619777494124),
                                             com)
target_map = target_map.rotate_by_axis_angle(0, 1, 0,
                                             np.rad2deg(0.0005038746980934731),
                                             com)
target_map = target_map.rotate_by_axis_angle(0, 0, 1,
                                             np.rad2deg(2.125868534775962),
                                             com)

# translate along x, y, z
target_map = target_map.translate(-42, -58, 5)

# save map
target_map.write_to_MRC_file('moved.mrc')  # Writing out to MRC file