Ejemplo n.º 1
0
    def calc_superposition(self, tls):
        plist = []
        msd = 0.0
        segment = tls.segment

        for frag1 in segment.iter_fragments():
            try:
                frag2 = self.srctgt_equiv[frag1]
            except KeyError:
                continue
            for name in const.SUPER_ATOMS:
                atm1 = frag1.get_atom(name)
                atm2 = frag2.get_atom(name)
                if atm1 == None or atm2 == None:
                    console.stdoutln("EEK! No Equivalent Atom %s" % (atm1))
                    continue
                plist.append((atm1.position, atm2.align_position))
                d = atm1.position - atm2.align_position
                msd += numpy.dot(d, d)

        rmsd_pre_alignment = math.sqrt(msd / len(plist))
        tls.rmsd_pre_alignment = rmsd_pre_alignment

        sresult = Superposition.SuperimposePositions(plist)
        tls.sresult = sresult

        rotation = math.degrees(2.0 * math.acos(sresult.Q[0]))
        if rotation > 180.0:
            rotation = 360.0 - rotation

        fragstr = "%s:%s-%s" % (self.chain.chain_id, tls.frag_id1,
                                tls.frag_id2)
        console.stdoutln(
            "TLS Group::%20s  Num Atoms::%4d  RMSD PRE ALIGN::%6.2f  RMSD::%6.2f  TRANSORM ROTATION::%6.2f"
            %
            (fragstr, len(plist), rmsd_pre_alignment, sresult.rmsd, rotation))

        ## screw displacement vector
        vscrew = AtomMath.normalize(
            numpy.array([sresult.Q[1], sresult.Q[2], sresult.Q[3]], float))
        console.stdoutln("superposition rotation vector: %s" % (vscrew))
        tls.superposition_vscrew = vscrew * rotation

        ## fit the isotropic TLS model to the group
        evals, evecs = numpy.linalg.eig(tls.tls_group.itls_L)

        for i in (0, 1, 2):
            eval = evals[i]
            evec = evecs[i]

            lname = "L%d_eigen_val" % (i)

            if (eval * Constants.RAD2DEG2) < 1.0:
                continue

            ang = min(calc_angle(evec, vscrew), calc_angle(-evec, vscrew))

            console.stdoutln("%s  magnitude::%6.2f  vector angle::%6.2f" %
                             (lname, eval * Constants.RAD2DEG2, ang))
Ejemplo n.º 2
0
    def calc_superposition(self, tls):
        plist = []
        msd = 0.0
        segment = tls.segment

        for frag1 in segment.iter_fragments():
            try:
                frag2 = self.srctgt_equiv[frag1]
            except KeyError:
                continue
            for name in SUPER_ATOMS:
                atm1 = frag1.get_atom(name)
                atm2 = frag2.get_atom(name)
                if atm1 == None or atm2 == None:
                    console.stdoutln("EEK! No Equivalent Atom %s" % (atm1))
                    continue
                plist.append((atm1.position, atm2.align_position))
                d = atm1.position - atm2.align_position
                msd += numpy.dot(d,d)
                    
        rmsd_pre_alignment = math.sqrt(msd / len(plist))
        tls.rmsd_pre_alignment = rmsd_pre_alignment

        sresult = Superposition.SuperimposePositions(plist)
        tls.sresult = sresult

        rotation = math.degrees(2.0 * math.acos(sresult.Q[0]))
        if rotation > 180.0:
            rotation = 360.0 - rotation

        fragstr = "%s:%s-%s" % (self.chain.chain_id, tls.frag_id1, tls.frag_id2)
        console.stdoutln(
            "TLS Group::%20s  Num Atoms::%4d  RMSD PRE ALIGN::%6.2f  RMSD::%6.2f  TRANSORM ROTATION::%6.2f" % (
            fragstr, len(plist), rmsd_pre_alignment, sresult.rmsd, rotation))

        ## screw displacement vector
        vscrew = AtomMath.normalize(numpy.array([sresult.Q[1],sresult.Q[2],sresult.Q[3]], float))
        console.stdoutln("superposition rotation vector: %s" % (vscrew))
        tls.superposition_vscrew = vscrew * rotation

        ## fit the isotropic TLS model to the group
        evals, evecs = numpy.linalg.eig(tls.tls_group.itls_L)

        for i in (0,1,2):
            eval = evals[i]
            evec = evecs[i]
            
            lname = "L%d_eigen_val" % (i)

            if (eval * Constants.RAD2DEG2) < 1.0:
                continue

            ang = min(calc_angle(evec, vscrew), calc_angle(-evec, vscrew))

            console.stdoutln("%s  magnitude::%6.2f  vector angle::%6.2f" % (
                lname, eval*Constants.RAD2DEG2, ang))
Ejemplo n.º 3
0
    def write_data_file(self):
        """Generate the data file and return the filename.
        """
        nrows = len(self.cpartition.chain)
        ncols = 1 + 3 * self.cpartition.num_tls_segments()
        tbl = table.StringTable(nrows, ncols, "?")

        mpred = lambda f: f.fragment_id
        frag_id_iter = itertools.imap(mpred, self.cpartition.chain.iter_fragments())
        tbl.set_column(0, 0, frag_id_iter)

        for itls, tls in enumerate(self.cpartition.iter_tls_segments()):
            tls_group = tls.tls_group
            tls_info = tls.model_tls_info
            O = tls_info["COR"]

            for frag in tls.iter_fragments():
                ## FIXME: This should be able to handle either one
                atm = frag.get_atom("CA")  ## for amino acids
                # atm = frag.get_atom("P") ## for nucleic acids
                if atm is None:
                    continue

                # if frag.get_atom("CA") is not None:
                #    atm = frag.get_atom("CA")
                #    console.stdoutln("CA_ATOM: %s" % str(atm))

                # elif frag.get_atom("P") is not None:
                #    atm = frag.get_atom("P")

                i = frag.ifrag

                for n, Lx_val, Lx_vec, Lx_rho, Lx_pitch in [
                    (0, "L1_eigen_val", "L1_eigen_vec", "L1_rho", "L1_pitch"),
                    (1, "L2_eigen_val", "L2_eigen_vec", "L2_rho", "L2_pitch"),
                    (2, "L3_eigen_val", "L3_eigen_vec", "L3_rho", "L3_pitch"),
                ]:

                    Lval = tls_info[Lx_val]
                    Lvec = tls_info[Lx_vec]
                    Lrho = tls_info[Lx_rho]
                    Lpitch = tls_info[Lx_pitch]

                    if numpy.allclose(Lval, 0.0):
                        continue

                    dvec = TLS.calc_LS_displacement(O, Lval, Lvec, Lrho, Lpitch, atm.position, conf.ADP_PROB)
                    tbl[i, 1 + 3 * itls + n] = AtomMath.length(dvec)

        flatfile_write(
            "LibrationAnalysis: data", "LIAN", "DATA", str(tbl), self.chain.chain_id, self.cpartition.num_tls_segments()
        )

        open(self.txt_path, "w").write(str(tbl))
Ejemplo n.º 4
0
    def write_data_file(self):
        """Generate the data file and return the filename.
        """
        nrows = len(self.cpartition.chain)
        ncols = 1 + 3 * self.cpartition.num_tls_segments()
        tbl = table.StringTable(nrows, ncols, "?")

        mpred = lambda f: f.fragment_id
        frag_id_iter = itertools.imap(mpred, self.cpartition.chain.iter_fragments())
        tbl.set_column(0, 0, frag_id_iter)

        for itls, tls in enumerate(self.cpartition.iter_tls_segments()):
            tls_group = tls.tls_group
            tls_info = tls.model_tls_info
            O = tls_info["COR"]

            for frag in tls.iter_fragments():
                atm = frag.get_atom("CA")
                if atm is None:
                    continue

                i = frag.ifrag

                for n, Lx_val, Lx_vec, Lx_rho, Lx_pitch in [
                    (0, "L1_eigen_val", "L1_eigen_vec", "L1_rho", "L1_pitch"),
                    (1, "L2_eigen_val", "L2_eigen_vec", "L2_rho", "L2_pitch"),
                    (2, "L3_eigen_val", "L3_eigen_vec", "L3_rho", "L3_pitch") ]:

                    Lval   = tls_info[Lx_val]
                    Lvec   = tls_info[Lx_vec]
                    Lrho   = tls_info[Lx_rho]
                    Lpitch = tls_info[Lx_pitch]

                    if numpy.allclose(Lval, 0.0):
                        continue

                    dvec = TLS.calc_LS_displacement(O, Lval, Lvec, Lrho, Lpitch, atm.position, settings.ADP_PROB)
                    tbl[i, 1 + 3*itls + n] = AtomMath.length(dvec)

        open(self.txt_path, "w").write(str(tbl))
Ejemplo n.º 5
0
    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
Ejemplo n.º 6
0
    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
Ejemplo n.º 7
0
def calc_directional_overlap(a, b):
    cos_ab = numpy.dot(a, b) / (AtomMath.length(a) * AtomMath.length(b))
    if cos_ab < 0.0:
        return 0.0
    return abs(cos_ab)
Ejemplo n.º 8
0
def calc_angle(a, b):
    cos_ab = numpy.dot(a, b)/ (AtomMath.length(a) * AtomMath.length(b))
    return Constants.RAD2DEG * abs(math.acos(cos_ab))
Ejemplo n.º 9
0
def rt_random2(T1, T2):
    theta = (random.random() - 0.5) * math.pi
    R = AtomMath.rmatrixu(random_vec(), theta)
    T1R = numpy.dot(numpy.dot(R, T1), numpy.transpose(R))
    T2R = numpy.dot(numpy.dot(R, T2), numpy.transpose(R))
    return T1, T2
Ejemplo n.º 10
0
def rt_random(T):
    theta = (random.random() - 0.5) * math.pi
    R = AtomMath.rmatrixu(random_vec(), theta)
    return numpy.dot(numpy.dot(R, T), numpy.transpose(R))
Ejemplo n.º 11
0
def random_vec():
    rcoord = lambda: random.random() - 0.5
    return AtomMath.normalize(numpy.array([rcoord(), rcoord(), rcoord()], float))
Ejemplo n.º 12
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]))