def cee_way(): m1 = sasmol.SasMol(0) m1.read_pdb('min3.pdb') natoms = m1.natoms() resid = m1.resid() name = m1.name() nresidues = m1.resid()[-1] - m1.resid()[0] + 1 flexible_residues = numpy.arange(2, 8).tolist() # print 'getting rotation indices for molecule' residue_rotation_indices = {} residue_rotation_mask = {} # print 'number of flexible residues = ',len(flexible_residues) nflexible = len(flexible_residues) atomlist = numpy.arange(0, natoms).tolist() #import cee_mask import mask farray = numpy.zeros((nflexible, natoms), numpy.int32) nresidues = int(nresidues) mask.get_mask_array(farray, name, resid, flexible_residues, nresidues) for i in xrange(nflexible): for j in xrange(natoms): if (farray[i][j] != 0): print farray[i][j],
def lam_way(): # import StringFunction m1 = sasmol.SasMol(0) m1.read_pdb('min3.pdb') natoms = m1.natoms() aresid = m1.resid() aname = m1.name() nresidues = m1.resid()[-1] - m1.resid()[0] + 1 flexible_residues = numpy.arange(2, 8).tolist() print 'getting rotation indices for molecule' residue_rotation_indices = {} residue_rotation_mask = {} print 'number of flexible residues = ', len(flexible_residues) atomlist = numpy.arange(0, natoms).tolist() for q0 in xrange(2, nresidues): if q0 in flexible_residues: print q0, sys.stdout.flush() previous_amino_acid = q0 - 1 this_amino_acid = q0 next_amino_acid = q0 + 1 refatm = '(resid == ' + str( previous_amino_acid) + ' and name == "C")' refatm += ' or (resid == ' + str( this_amino_acid) + ' and name == "N")' refatm += ' or (resid == ' + str( this_amino_acid) + ' and name == "CA")' refatm += ' or (resid == ' + str( this_amino_acid) + ' and name == "C")' refatm += ' or (resid == ' + str( next_amino_acid) + ' and name == "N")' preliminary_mask_array = [] for i in xrange(natoms): name = aname[i] resid = aresid[i] # ans=StringFunction.StringFunction(refatm, independent_variables=('name','resid')) if (ans(name, resid) == 1): # print q0,i preliminary_mask_array.append(1) else: preliminary_mask_array.append(0) mask_array = numpy.array(preliminary_mask_array, numpy.int32) residue_rotation_mask[q0] = mask_array.tolist()
def list_way(): m1 = sasmol.SasMol(0) m1.read_pdb('min3.pdb') moltype = m1.moltype() natoms = m1.natoms() resid = m1.resid() name = m1.name() nresidues = m1.resid()[-1] - m1.resid()[0] + 1 flexible_residues = numpy.arange(2, 8).tolist() print 'getting rotation indices for molecule' residue_rotation_indices = {} residue_rotation_mask = {} print 'number of flexible residues = ', len(flexible_residues) atomlist = numpy.arange(0, natoms).tolist() for q0 in xrange(2, nresidues): if q0 in flexible_residues: print q0, sys.stdout.flush() previous_amino_acid = q0 - 1 this_amino_acid = q0 next_amino_acid = q0 + 1 refatm = '(resid[i] == ' + str( previous_amino_acid) + ' and name[i] == "C")' refatm += ' or (resid[i] == ' + str( this_amino_acid) + ' and name[i] == "N")' refatm += ' or (resid[i] == ' + str( this_amino_acid) + ' and name[i] == "CA")' refatm += ' or (resid[i] == ' + str( this_amino_acid) + ' and name[i] == "C")' refatm += ' or (resid[i] == ' + str( next_amino_acid) + ' and name[i] == "N")' torf = [eval(refatm) for i in atomlist]
def old_way(): m1 = sasmol.SasMol(0) m1.read_pdb('min3.pdb') moltype = m1.moltype() natoms = m1.natoms() nresidues = m1.resid()[-1] - m1.resid()[0] + 1 flexible_residues = numpy.arange(2, 8).tolist() print 'getting rotation indices for molecule' residue_rotation_indices = {} residue_rotation_mask = {} print 'number of flexible residues = ', len(flexible_residues) for q0 in xrange(2, nresidues): if q0 in flexible_residues: print q0, sys.stdout.flush() previous_amino_acid = q0 - 1 this_amino_acid = q0 next_amino_acid = q0 + 1 refatm = '(resid[i] == ' + str( previous_amino_acid) + ' and name[i] == "C")' refatm += ' or (resid[i] == ' + str( this_amino_acid) + ' and name[i] == "N")' refatm += ' or (resid[i] == ' + str( this_amino_acid) + ' and name[i] == "CA")' refatm += ' or (resid[i] == ' + str( this_amino_acid) + ' and name[i] == "C")' refatm += ' or (resid[i] == ' + str( next_amino_acid) + ' and name[i] == "N")' error, mask = m1.get_subset_mask(refatm) indices = m1.get_indices_from_mask(mask) residue_rotation_indices[q0] = indices.tolist() residue_rotation_mask[q0] = mask.tolist()
''' SASSIE Copyright (C) 2011 Joseph E. Curtis This program comes with ABSOLUTELY NO WARRANTY; This is free software, and you are welcome to redistribute it under certain conditions; see http://www.gnu.org/licenses/gpl-3.0.html for details. ''' import sys, numpy, time sys.path.append('./') import dcdio import sasmol A = sasmol.SasMol(0) A.read_pdb('min3.pdb') natoms = A.natoms() x = A.coor()[:, 0] y = A.coor()[:, 1] z = A.coor()[:, 2] #x=[1.0,2.0,3.0] ; y=[1.0,2.0,3.0] ; z=[1.0,2.0,3.0] x = numpy.array(x, numpy.float32) y = numpy.array(y, numpy.float32) z = numpy.array(z, numpy.float32) filename = 'c7.dcd' fp = dcdio.open_dcd_write(filename) nset = 200
def init_child(self, descriptor): ''' This method allows one to create a list of SasMol objects that are defined by the input descriptor. usage: This is a way to create a mask to be used somewhere else: m1=sasmol.SasMol(0) ### create a molecule m1 m1.read_pdb(filename) ### read in variables, coor, etc. m1.initialize_children() ### set up the masks etc. . . . do stuff . . . This initializes the following "children" with their masks already defined to the "parent" molecule names() : names_mask() resnames() : resnames_mask() resids() : resids_mask() chains() : chains_mask() segnames() : segnames_mask() occupancies() : occupancies_mask() betas() : betas_mask() elements() : elements_mask() The objects on the left contain the unique values and the objects on the right contain the masks that have the indices to extract the information for each unique value from the parent molecule. NOTE: the pluarity of the words is chosen for a reason to distinguish the singular words used to keep track of the parent variables (name --> name[i] for each atom, while names --> corresponds to the unique names in the parent: len(names) <= len(name)) For "min3.pdb" if one wants to know the unique elements you would type: m1.elements() which yields: ['N', 'H', 'C', 'O', 'S', 'ZN'] So, given a pre-defined object that has atomic information initialized by reading in the PDB file and intializing all children as shown above, one can get a list of subset objects for each type of element by typing: element_molecules = m1.init_child('elements') then you could parse the full-subset molecule as its own entity com = element_molecules[0].calccom(0) which would give the center of mass for all the "N" atoms in the parent molecule. Another example would be to get the COM of each amino acid in a protein. residue_molecules = m1.init_child('resids') for i in xrange(m1.number_of_resids()): print residue_molecules[i].calccom(0) NOTE: coordinates will have to be updated separately using get_coor_using_mask ... using the mask(s) generated by sasio.initialize_children() ''' import sasmol at = 'len(self.' + descriptor + '())' number_of_objects = eval(at) frame = 0 object_list = [] for i in xrange(number_of_objects): new_object = sasmol.SasMol(0) at = 'self.' + descriptor + '_mask()[' + str(i) + ']' mask = eval(at) error = self.copy_molecule_using_mask(new_object, mask, frame) object_list.append(new_object) return object_list
def new_way(): m1 = sasmol.SasMol(0) m1.read_pdb('min3.pdb') moltype = m1.moltype() natoms = m1.natoms() aresid = m1.resid() aname = m1.name() nresidues = m1.resid()[-1] - m1.resid()[0] + 1 flexible_residues = numpy.arange(2, 8).tolist() print 'getting rotation indices for molecule' residue_rotation_indices = {} residue_rotation_mask = {} print 'number of flexible residues = ', len(flexible_residues) atomlist = numpy.arange(0, natoms).tolist() for q0 in xrange(2, nresidues): if q0 in flexible_residues: print q0, sys.stdout.flush() previous_amino_acid = q0 - 1 this_amino_acid = q0 next_amino_acid = q0 + 1 #refatm = '(resid[i] == '+str(previous_amino_acid)+' and name[i] == "C")' #refatm += ' or (resid[i] == '+str(this_amino_acid)+' and name[i] == "N")' #refatm += ' or (resid[i] == '+str(this_amino_acid)+' and name[i] == "CA")' #refatm += ' or (resid[i] == '+str(this_amino_acid)+' and name[i] == "C")' #refatm += ' or (resid[i] == '+str(next_amino_acid)+' and name[i] == "N")' refatm = '(resid == ' + str( previous_amino_acid) + ' and name == "C")' refatm += ' or (resid == ' + str( this_amino_acid) + ' and name == "N")' refatm += ' or (resid == ' + str( this_amino_acid) + ' and name == "CA")' refatm += ' or (resid == ' + str( this_amino_acid) + ' and name == "C")' refatm += ' or (resid == ' + str( next_amino_acid) + ' and name == "N")' preliminary_mask_array = [] for i in xrange(natoms): name = aname[i] resid = aresid[i] ans = StringFunction_0(refatm, name=name, resid=resid) if (ans(name, resid) == 1): # print q0,i preliminary_mask_array.append(1) else: preliminary_mask_array.append(0) # torf=[StringFunction('refatm',independent_variable='i') for i in atomlist] mask_array = numpy.array(preliminary_mask_array, numpy.int32) # error,mask = m1.get_subset_mask(refatm) ; indices = m1.get_indices_from_mask(mask) # residue_rotation_indices[q0] = indices.tolist() residue_rotation_mask[q0] = mask_array.tolist()