def __init__(self, PDBlines, parent, atoms): Molecule.__init__(self, PDBlines) self.parent = parent self.atoms = atoms for atom in atoms: atom.parent = self line = PDBlines[0] self.res_type1 = string.strip(line[17:20]) self.res_number = string.atoi(line[23:26]) self.is_Nterm = 0 self.is_Cterm = 0 self.has_central_pt = 0 self.atoms_dict = {} for atom in self.atoms: self.atoms_dict[atom.atom_type] = atom if atom.atom_type[:2] == 'C3': self.central_pt = Point(atom.x, atom.y, atom.z) self.central_atom = atom self.x = atom.x self.y = atom.y self.z = atom.z self.has_central_pt = 1 self.is_Nterm = 0 self.is_Cterm = 0 self.vtk_arg_list = {} trace_args = {'color': [0.1, 0.1, 1.0], 'opacity': 1.0} self.vtk_arg_list['trace'] = trace_args self.visible = 0 self.transparent = 0
def fill_densities(self, distance_cutoff=9.0, force_rewrite=0): filename = self.parent.get_filename_by_extension( '.ads', self.chain_name) create_new = 0 if force_rewrite: create_new = 1 else: try: densities_file = open(filename) except IOError: create_new = 1 if create_new: if self.x_table == None: self.build_futamura_intersection_table(distance_cutoff) print 'filling densities' atom_count = 0.0 densities = [] max_count = 0 for atom in self.atoms: data_list = self.x_table['%s' % (atom.atom_number)] atom_count = 0 for data_ind in range(len(data_list)): atom_data = self.x_table['%s' % (atom.atom_number)] p = Point(data_list[data_ind][0], data_list[data_ind][1], data_list[data_ind][2]) d = atom.dist(p) if d < distance_cutoff: atom_count = atom_count + 1 densities.append(atom_count) if atom_count > max_count: max_count = atom_count for i in range(len(self.atoms)): self.atoms[i].features['atomic_density'] = (densities[i] + 0.0) / max_count densities_file = open(filename, 'w') for atm in self.atoms: densities_file.write('%s\n' % (atm.features['atomic_density'])) densities_file.close() else: # else read the contacts_file to fill the contact_list for atom in self.atoms: buffer = densities_file.readline() if len(buffer) == 0: break atom.features['atomic_density'] = string.atof(buffer) densities_file.close()
def fill_pseudo_sidechains(self, type=1): """ calculate a single coordinate to represent the sidechain. type 0 calculates 2 A out from the bisector of a triangle formed between three consecutive alpha carbons. If the residue terminates a structural fragment, it is assigned to the average of its non-H sidechain atoms, or to the central_pt's position if there are no sidechain atoms. type 1 calculates the average coordinate from all non-H sidechain atoms. """ if type == 0: for rez_index in range(len(self.residues)): if not self.residues[rez_index].has_central_pt: continue if self.residues[rez_index].is_Nterm == 1 or self.residues[rez_index].is_Cterm == 1: self.residues[rez_index].pseudo_sidechain = copy.deepcopy(self.residues[rez_index].central_pt) continue a1 = self.residues[rez_index-1].central_pt a2 = self.residues[rez_index].central_pt a3 = self.residues[rez_index+1].central_pt l1 = self.residues[rez_index].central_pt.dist(self.residues[rez_index-1].central_pt) l2 = self.residues[rez_index].central_pt.dist(self.residues[rez_index+1].central_pt) if l1<l2: x = ((l2/l1)*(a1.x-a2.x)) + a2.x y = ((l2/l1)*(a1.y-a2.y)) + a2.y z = ((l2/l1)*(a1.z-a2.z)) + a2.z tp = Point(x,y,z) x = (a3.x + tp.x)/2 y = (a3.y + tp.y)/2 z = (a3.z + tp.z)/2 mp = Point(x,y,z) else: x = ((l1/l2)*(a3.x-a2.x)) + a2.x y = ((l1/l2)*(a3.y-a2.y)) + a2.y z = ((l1/l2)*(a3.z-a2.z)) + a2.z tp = Point(x,y,z) x = a1.x + tp.x / 2 y = a1.y + tp.y / 2 z = a1.z + tp.z / 2 mp = Point(x,y,z) l2_mp_dist = a2.dist(mp) lmp_B_dist = l2_mp_dist + 2.0 x = ( (lmp_B_dist/l2_mp_dist) * ( a2.x-mp.x) ) + mp.x y = ( (lmp_B_dist/l2_mp_dist) * ( a2.y-mp.y) ) + mp.y z = ( (lmp_B_dist/l2_mp_dist) * ( a2.z-mp.z) ) + mp.z self.residues[rez_index].pseudo_sidechain = Point(x,y,z) elif type == 1: for rez in self.residues: stuff = rez.get_average_sidechain_position() rez.pseudo_sidechain = Point(stuff[0],stuff[1],stuff[2])
def point_line_distance(self, a1, a2): """ calculate p4, the atom on the line between atoms p1 and p2 to which atom p3 is perpendicular then return the distance between p3 and p4. 1_____3_____2 is relevant, but, 3 1___________2 and 1___________2 3 are not. returns -1 if p3 is not perpendicular to p1-p2 between them. however, if 3 is the alpha carbon of 1 or 2, shielding is surely not as bad when the alpha carbon is just to the inside of the line. so, a simple weighting function attempts to fix the problem by doubling the distance. Therefore lower shielding is reported when considering the alpha carbons of the amino acids being investigated. """ score = Point.point_line_distance(self, p1.central_point, p2.central_point) if self.atom_type == 'CA': if self.res_number == a1.res_number and self.chain_name == a1.chain_name: return 2*score elif self.res_number == a2.res_number and self.chain_name == a2.chain_name: return 2*score
def point_line_distance(self, a1, a2): """ calculate p4, the atom on the line between atoms p1 and p2 to which atom p3 is perpendicular then return the distance between p3 and p4. 1_____3_____2 is relevant, but, 3 1___________2 and 1___________2 3 are not. returns -1 if p3 is not perpendicular to p1-p2 between them. however, if 3 is the alpha carbon of 1 or 2, shielding is surely not as bad when the alpha carbon is just to the inside of the line. so, a simple weighting function attempts to fix the problem by doubling the distance. Therefore lower shielding is reported when considering the alpha carbons of the amino acids being investigated. """ score = Point.point_line_distance(self, p1.central_point, p2.central_point) if self.atom_type == 'CA': if self.res_number == a1.res_number and self.chain_name == a1.chain_name: return 2 * score elif self.res_number == a2.res_number and self.chain_name == a2.chain_name: return 2 * score
def get_central_pt(self): # for use with classes amino acid and nucleotide only new_pt = Point(self.central_pt.x, self.central_pt.y, self.central_pt.z) return new_pt
def __init__(self, PDBlines): self.atoms = [] # create Atom objects from the lines # calculate the centroid at the same time centroid = [0.0, 0.0, 0.0] self.pdb_lines = PDBlines for line in PDBlines: new_atom = Atom(self, line) new_atom.data['parent_molecule'] = self self.add_atom(new_atom) centroid[0] = centroid[0] + new_atom.x centroid[1] = centroid[1] + new_atom.y centroid[2] = centroid[2] + new_atom.z self.centroid = Point(centroid[0] / len(self.atoms), centroid[1] / len(self.atoms), centroid[2] / len(self.atoms)) line = PDBlines[0] self.chain_name = string.strip(line[21:22]) self.res_type = string.strip(line[17:20]) self.selected = 1 # start everything out as selected self.visible = 1 # and visible self.atom_points = 'None' # holds vtkPoint # stuff for distances for bonds self.C_types = { 'C': 1.80, 'O': 1.65, 'N': 1.70, 'S': 2.05, 'P': 2.10, 'H': 1.35, 'Z': 2.5 } self.O_types = { 'C': 1.65, 'O': 1.45, 'N': 1.65, 'S': 1.70, 'P': 1.85, 'H': 1.25, 'Z': 2.5 } self.N_types = { 'C': 1.70, 'O': 1.65, 'N': 1.70, 'S': 2.05, 'P': 2.10, 'H': 1.30, 'Z': 2.5 } self.S_types = { 'C': 2.05, 'O': 1.70, 'N': 2.05, 'S': 1.75, 'P': 2.10, 'H': 1.65, 'Z': 2.5 } self.P_types = { 'C': 2.10, 'O': 1.85, 'N': 2.10, 'S': 2.10, 'P': 2.30, 'H': 1.75, 'Z': 2.5 } self.H_types = { 'C': 1.35, 'O': 1.25, 'N': 1.30, 'S': 1.65, 'P': 1.75, 'H': 1.05, 'Z': 2.5 } self.Z_types = { 'C': 2.5, 'O': 2.50, 'N': 2.50, 'S': 2.50, 'P': 2.50, 'H': 2.50, 'Z': 2.5 } self.common_atoms_list = ['C', 'O', 'N', 'S', 'P', 'H', 'Z'] self.vtk_arg_list = {} volume_args = { 'visualize': 0, 'currently_on': 0, 'specular': 0.3, 'specular_power': 30, 'representation': 'surface' } atoms_args = { 'visualize': 0, 'currently_on': 0, 'width': 0.1, 'sticks_width': 0.1, 'sticks_sides': 11, 'representation': 'sticks' } self.vtk_arg_list['volume'] = volume_args self.vtk_arg_list['atoms'] = atoms_args self.x_table = None self.features = {} self.data = {}
def __init__(self, parent, PDBlines, atoms): Molecule.__init__(self, PDBlines) self.atoms = atoms for atom in self.atoms: atom.parent = self self.parent = parent # load amino acid properties types = { 'ALA': 'A', 'CYS': 'C', 'CYD': 'C', 'CYX': 'C', 'CYZ': 'C', 'ASP': 'D', 'GLU': 'E', 'PHE': 'F', 'GLY': 'G', 'HIS': 'H', 'HID': 'H', 'HIE': 'H', 'ILE': 'I', 'LYS': 'K', 'LEU': 'L', 'MET': 'M', 'ASN': 'N', 'PRO': 'P', 'GLN': 'Q', 'ARG': 'R', 'SER': 'S', 'THR': 'T', 'VAL': 'V', 'TRP': 'W', 'TYR': 'Y' } self.res_type1 = types[self.res_type] line = PDBlines[0] self.res_number = string.atoi(line[23:26]) # store alpha carbon coordinates self.has_central_pt = 0 self.atoms_dict = {} for atom in self.atoms: self.atoms_dict[atom.atom_type] = atom if atom.atom_type == 'CA': self.central_pt = Point(atom.x, atom.y, atom.z) self.central_atom = atom self.x = atom.x self.y = atom.y self.z = atom.z self.has_central_pt = 1 try: self.atoms_dict['CA'] except KeyError: print "Warning: %s%d has no apparent alpha carbon" % ( self.res_type, self.res_number) types = { 'ALA': 71.09, 'CYS': 103.15, 'CYD': 103.15, 'CYX': 103.15, 'CYZ': 103.15, 'ASP': 115.09, 'GLU': 129.12, 'PHE': 147.18, 'GLY': 57.05, 'HIS': 137.14, 'HID': 137.14, 'HIE': 137.14, 'ILE': 113.16, 'LYS': 128.17, 'LEU': 113.16, 'MET': 131.19, 'ASN': 114.11, 'PRO': 97.12, 'GLN': 128.14, 'ARG': 156.19, 'SER': 87.08, 'THR': 101.11, 'VAL': 99.14, 'TRP': 186.21, 'TYR': 163.18 } self.mw = types[self.res_type] # these get fixed later on in initialization by class Protein self.is_Nterm = 0 self.is_Cterm = 0 # create the vtk_args_list # [onoff, width, color, splines, sides, specular, specularpower] self.vtk_arg_list = { } # this gets overridden because residue doesnt need everything in Molecule trace_args = {'color': [0.1, 0.1, 1.0], 'opacity': 1.0} self.vtk_arg_list['trace'] = trace_args self.visible = 0 self.transparent = 0