def iter_fragment_range(chain, frag_id1, frag_id2): for frag in chain.iter_fragments(): if Structure.fragment_id_lt(frag.fragment_id, frag_id1): continue if Structure.fragment_id_gt(frag.fragment_id, frag_id2): break yield frag
def copy_struct(self, struct, chain): """Make a copy of the argument structure to use for generating the animation. Only copy the chain specified in chain_id. """ cp_struct = Structure.Structure(structure_id = struct.structure_id) chain_id = chain.chain_id for chain in struct.iter_chains(): ## TODO: Move "200" to conf.py, 2009-06-19 if chain.chain_id == chain_id or chain.count_fragments() < 200: include_chain = True else: include_chain = False for frag in chain.iter_fragments(): ## skip all waters if frag.is_water() == True: continue elif frag.is_standard_residue() == True and include_chain: for atm in iter_filter_atoms(frag.iter_atoms()): cp_atom = Structure.Atom( chain_id = atm.chain_id, fragment_id = atm.fragment_id, res_name = atm.res_name, element = atm.element, name = atm.name, temp_factor = atm.temp_factor, occupancy = atm.occupancy, position = atm.position.copy()) cp_struct.add_atom(cp_atom, True) elif frag.is_standard_residue() == False: for atm in frag.iter_atoms(): cp_atom = Structure.Atom( chain_id = atm.chain_id, fragment_id = atm.fragment_id, res_name = atm.res_name, element = atm.element, name = atm.name, temp_factor = atm.temp_factor, occupancy = atm.occupancy, position = atm.position.copy()) cp_struct.add_atom(cp_atom, True) cp_struct.sort() return cp_struct
def segment_range_cmp(segrange1, segrange2): """Compare two fragment ids. Performs a proper less than comparison of frament_id strings according to their sequence number, then insertion code. Split a string fragment_id into a 2-tuple of: (sequence_num, insertion_code) """ return Structure.fragment_id_cmp(segrange1[0], segrange2[0])
def ConstructSegmentForAnalysis(raw_chain): """Returns a list of Segment instance from the Chain instance which is properly modified for use in the this application. """ ## Sets that atm.include attribute for each atom in the chains ## being analyzed by tlsmd for atm in raw_chain.iter_all_atoms(): atm.include = atom_selection.calc_include_atom(atm) ## ok, use the chain but use a segment and cut off ## any leading and trailing non-amino acid residues ## do not include a fragment with no included atoms naa = raw_chain.count_amino_acids() nna = raw_chain.count_nucleic_acids() if naa > nna: iter_residues = raw_chain.iter_amino_acids() elif nna > naa: iter_residues = raw_chain.iter_nucleic_acids() segment = Structure.Segment(chain_id = raw_chain.chain_id) for frag in iter_residues: for atm in frag.iter_all_atoms(): if atm.include: segment.add_fragment(frag) break ## apply data smooth if desired if conf.globalconf.adp_smoothing > 0: adp_smoothing.IsotropicADPDataSmoother(segment, conf.globalconf.adp_smoothing) ## this is useful: for each fragment in the minimization ## set a attribute for its index position for i, frag in enumerate(segment.iter_fragments()): frag.ifrag = i ## create a TLSModelAnalyzer instance for the chain, and ## attach the instance to the chain for use by the rest of the ## program segment.tls_analyzer = tlsmdmodule.TLSModelAnalyzer() xlist = atom_selection.chain_to_xmlrpc_list(segment.iter_all_atoms()) segment.tls_analyzer.set_xmlrpc_chain(xlist) return segment
def calc_inertia_tensor(atom_iter): """Calculate moment of inertia tensor at the centroid of the atoms. """ al = Structure.AtomList(atom_iter) centroid = al.calc_centroid() I = numpy.zeros((3, 3), float) for atm in al: x = atm.position - centroid I[0, 0] += x[1]**2 + x[2]**2 I[1, 1] += x[0]**2 + x[2]**2 I[2, 2] += x[0]**2 + x[1]**2 I[0, 1] += -x[0] * x[1] I[1, 0] += -x[0] * x[1] I[0, 2] += -x[0] * x[2] I[2, 0] += -x[0] * x[2] I[1, 2] += -x[1] * x[2] I[2, 1] += -x[1] * x[2] evals, evecs = numpy.linalg.eig(I) elist = [(evals[0], evecs[0]), (evals[1], evecs[1]), (evals[2], evecs[2])] elist.sort() R = numpy.array((elist[0][1], elist[1][1], elist[2][1]), float) ## make sure the tensor uses a right-handed coordinate system if numpy.allclose(numpy.linalg.det(R), -1.0): I = numpy.identity(3, float) I[0, 0] = -1.0 R = numpy.dot(I, R) assert numpy.allclose(numpy.linalg.det(R), 1.0) return centroid, R
def displace_model(self, model, tls, phase): """Displace the given model by the tls. """ tls_info = tls.model_tls_info cor = tls_info["COR"] for n, Lx_rmsd, Lx_vec, Lx_rho, Lx_pitch in [ (1, "L1_rmsd", "L1_eigen_vec", "L1_rho", "L1_pitch"), (2, "L2_rmsd", "L2_eigen_vec", "L2_rho", "L2_pitch"), (3, "L3_rmsd", "L3_eigen_vec", "L3_rho", "L3_pitch") ]: Lrmsd = tls_info[Lx_rmsd] Lvec = tls_info[Lx_vec] Lrho = tls_info[Lx_rho] Lpitch = tls_info[Lx_pitch] ## pre-calculations for screw displacement Lorigin = cor + Lrho Lrot = Gaussian.GAUSS3C[settings.ADP_PROB] * Lrmsd * phase D = AtomMath.dmatrixu(Lvec, Lrot) d_screw = (Lrot * Lpitch) * Lvec if n == 1: chain_id = self.L1_chain.chain_id elif n == 2: chain_id = self.L2_chain.chain_id elif n == 3: chain_id = self.L3_chain.chain_id chain = model.get_chain(chain_id) for frag_id1, frag_id2 in tls.iter_segment_ranges(): for frag in Structure.iter_fragments(chain.iter_fragments(), frag_id1, frag_id2): for atm in frag.iter_atoms(): d = numpy.dot(D, atm.position - Lorigin) + d_screw atm.position += d
def displace_model(self, model, tls, phase): """Displace the given model by the tls. """ tls_info = tls.model_tls_info cor = tls_info["COR"] for n, Lx_rmsd, Lx_vec, Lx_rho, Lx_pitch in [ (1, "L1_rmsd", "L1_eigen_vec", "L1_rho", "L1_pitch"), (2, "L2_rmsd", "L2_eigen_vec", "L2_rho", "L2_pitch"), (3, "L3_rmsd", "L3_eigen_vec", "L3_rho", "L3_pitch") ]: Lrmsd = tls_info[Lx_rmsd] Lvec = tls_info[Lx_vec] Lrho = tls_info[Lx_rho] Lpitch = tls_info[Lx_pitch] ## pre-calculations for screw displacement Lorigin = cor + Lrho Lrot = Gaussian.GAUSS3C[settings.ADP_PROB] * Lrmsd * phase D = AtomMath.dmatrixu(Lvec, Lrot) d_screw = (Lrot * Lpitch) * Lvec if n==1: chain_id = self.L1_chain.chain_id elif n==2: chain_id = self.L2_chain.chain_id elif n==3: chain_id = self.L3_chain.chain_id chain = model.get_chain(chain_id) for frag_id1, frag_id2 in tls.iter_segment_ranges(): for frag in Structure.iter_fragments(chain.iter_fragments(), frag_id1, frag_id2): for atm in frag.iter_atoms(): d = numpy.dot(D, atm.position - Lorigin) + d_screw atm.position += d
def srlcmp(item1, item2): return Structure.fragment_id_cmp(item1[0][0], item2[0][0])
def displace_model(self, model, tls, phase, which_ntls, raw_r3d_file): """Displace the given model by the tls. """ tls_info = tls.model_tls_info cor = tls_info["COR"] ## figure out which libration eigenvalue is the largest and ## use that value in the animation. Christoph Champ, 2008-08-15 L1_val = float(tls_info["L1_eigen_val"]) * Constants.RAD2DEG2 L2_val = float(tls_info["L2_eigen_val"]) * Constants.RAD2DEG2 L3_val = float(tls_info["L3_eigen_val"]) * Constants.RAD2DEG2 max_libration = 0.00 for val in L1_val, L2_val, L3_val: if val >= max_libration: max_libration = val for n, Lx_rmsd, Lx_val, Lx_vec, Lx_rho, Lx_pitch in [ (1, "L1_rmsd", "L1_eigen_val", "L1_eigen_vec", "L1_rho", "L1_pitch"), (2, "L2_rmsd", "L2_eigen_val", "L2_eigen_vec", "L2_rho", "L2_pitch"), (3, "L3_rmsd", "L3_eigen_val", "L3_eigen_vec", "L3_rho", "L3_pitch") ]: Lrmsd = tls_info[Lx_rmsd] Lvec = tls_info[Lx_vec] Lrho = tls_info[Lx_rho] Lpitch = tls_info[Lx_pitch] Lval = tls_info[Lx_val] * Constants.RAD2DEG2 ## pre-calculations for screw displacement Lorigin = cor + Lrho Lrot = Gaussian.GAUSS3C[conf.ADP_PROB] * Lrmsd * phase D = AtomMath.dmatrixu(Lvec, Lrot) d_screw = (Lrot * Lpitch) * Lvec ## TODO: Add max(L) chain_id to ANIMATE.txt, 2009-08-06 if n == 1: chain_id = self.L1_chain.chain_id elif n == 2: chain_id = self.L2_chain.chain_id elif n == 3: chain_id = self.L3_chain.chain_id chain = model.get_chain(chain_id) for frag_id1, frag_id2 in tls.iter_segment_ranges(): for frag in Structure.iter_fragments(chain.iter_fragments(), frag_id1, frag_id2): for atm in frag.iter_atoms(): d = numpy.dot(D, atm.position - Lorigin) + d_screw atm.position += d atm.temp_factor = float(which_ntls) atm.element = str(model.model_id) ## raw input file for tlsanim2r3d->Raster3D ## E.g., "1 0 A 0 0 7.069 -24.991 -2.991" if Lval == max_libration: raw_r3d_file.write("1 ") else: raw_r3d_file.write("0 ") raw_r3d_file.write("%s %s %s %s %.3f %.3f %.3f\n" % ( model.model_id, self.L1_chain.chain_id, which_ntls, n, atm.position[0], atm.position[1], atm.position[2]))
def ConstructSegmentForAnalysis(raw_chain): """Returns a list of Segment instance from the Chain instance which is properly modified for use in the this application. """ console.debug_stdoutln(">tlsmd_analysis->ConstructSegmentForAnalysis(chain %s)" % ( raw_chain.chain_id)) ## NOTE: raw_chain = "Chain(1:A, Res(MET,1,A)...Res(VAL,50,A))" ## Sets that atm.include attribute for each atom in the chains ## being analyzed by tlsmd for atm in raw_chain.iter_all_atoms(): #atm.include = atom_selection.calc_include_atom(atm) atm.include = atom_selection.calc_include_atom(atm, reject_messages = True) ## ok, use the chain but use a segment and cut off ## any leading and trailing non-amino acid residues ## do not include a fragment with no included atoms naa = nna = ota = 0 naa = raw_chain.count_amino_acids() nna = raw_chain.count_nucleic_acids() ota = raw_chain.count_fragments() if naa > nna: ## Probably a protein with (possibly) some nucleic acids. iter_residues = raw_chain.iter_amino_acids() elif nna > naa: ## Probably a nucleic acid with (possibly) some amino acids. iter_residues = raw_chain.iter_nucleic_acids() if naa == 0 and nna == 0 and ota > 0: ## This chain does not have any amino or nucleic acids, so skip. return "" segment = Structure.Segment(chain_id = raw_chain.chain_id) for frag in iter_residues: for atm in frag.iter_all_atoms(): if atm.include: segment.add_fragment(frag) break ## apply data smooth if desired (default is "0") if conf.globalconf.adp_smoothing > 0: adp_smoothing.IsotropicADPDataSmoother(segment, conf.globalconf.adp_smoothing) ## this is useful: for each fragment in the minimization ## set an attribute for its index position for i, frag in enumerate(segment.iter_fragments()): ## NOTE (by Christoph): ## Example output: ## 0 : Res(MET,1,A) ## 1 : Res(ILE,2,A) ## ... frag.ifrag = i ## create a TLSModelAnalyzer instance for the chain, and attach the ## instance to the chain for use by the rest of the program segment.tls_analyzer = tlsmdmodule.TLSModelAnalyzer() xlist = atom_selection.chain_to_xmlrpc_list(segment.iter_all_atoms()) segment.tls_analyzer.set_xmlrpc_chain(xlist) ## INPUT : raw_chain = "Chain(1:A, Res(MET,1,A)...Res(VAL,50,A))" ## OUTPUT: segment = "Segment(1:A, Res(MET,1,A)...Res(VAL,50,A))" return segment
def segment_range_cmp(segrange1, segrange2): return Structure.fragment_id_cmp(segrange1[0], segrange2[0])