Exemple #1
0
def cms(s, sel):
    at = getAtomtypes()
    if at is None:
        msg().error(
            "Atom-types information not available, calculating average.")
    if s is None:
        return None
    s = Structure(s)
    s.setCarthesian()
    w = Vector(0.0, 0.0, 0.0)
    M = 0.0
    try:
        for i, nx, ny, nz in sel:
            if i < len(s) and i >= 0:
                try:
                    m = float(s.info.getRecordForAtom(i).mass)
                except:
                    m = float(
                        at.getRecordForElement(
                            s.info.getRecordForAtom(i).element).mass)
                w = w + m * (s[i] + nx * s.basis[0] + ny * s.basis[1] +
                             nz * s.basis[2])
                M = M + m
        w = (1.0 / M) * w
        return w
    except:
        msg().exception()
        msg().error("CMS not aplicable, calculating an average.")
        return average(s, sel)
Exemple #2
0
def last(s, sel):
    if s is None:
        return None
    s = Structure(s)
    s.setCarthesian()
    if len(sel):
        i, nx, ny, nz = sel[-1]
        if len(s) > i:
            return s[i] + nx * s.basis[0] + ny * s.basis[1] + nz * s.basis[2]
    return None
Exemple #3
0
def average(s, sel):
    if s is None:
        return None
    s = Structure(s)
    s.setCarthesian()
    w = Vector(0.0, 0.0, 0.0)
    n = 0
    for i, nx, ny, nz in sel:
        if i < len(s) and i >= 0:
            w = w + s[i] + nx * s.basis[0] + ny * s.basis[1] + nz * s.basis[2]
            n = n + 1
    w = (1.0 / float(n)) * w
    return w
    def updateCoord(self):
        s=self.getStructure()
        if s is not None:
            s=Structure(s)
            s.setCarthesian()
        sel=self.sel
        if len(sel)>1:
            try:
                i,nx,ny,nz=sel[0]
                v1=s[i]+s.basis[0]*nx+s.basis[1]*ny+s.basis[2]*nz
                i,nx,ny,nz=sel[1]
                v2=s[i]+s.basis[0]*nx+s.basis[1]*ny+s.basis[2]*nz
                l=(v1-v2).length()
                self.l1_entry.set_text("%14.8f"%l)
            except:
                self.l1_entry.set_text("")
        else:
            self.l1_entry.set_text("")
        if len(sel)>2:
            try:
                i,nx,ny,nz=sel[0]
                a=s[i]+s.basis[0]*nx+s.basis[1]*ny+s.basis[2]*nz
                i,nx,ny,nz=sel[1]
                b=s[i]+s.basis[0]*nx+s.basis[1]*ny+s.basis[2]*nz
                i,nx,ny,nz=sel[2]
                c=s[i]+s.basis[0]*nx+s.basis[1]*ny+s.basis[2]*nz
                l=(b-c).length()
                self.l2_entry.set_text("%14.8f"%l)
                angle=(a-b).angle(c-b)*180.0/pi
                self.a2_entry.set_text("%+7.4f"%angle)
            except:
                msg().exception()
                self.l2_entry.set_text("")
                self.a2_entry.set_text("")
        else:
            self.l2_entry.set_text("")
            self.a2_entry.set_text("")

        if len(sel)>3:
            try:
                i,nx,ny,nz=sel[0]
                a=s[i]+s.basis[0]*nx+s.basis[1]*ny+s.basis[2]*nz
                i,nx,ny,nz=sel[1]
                b=s[i]+s.basis[0]*nx+s.basis[1]*ny+s.basis[2]*nz
                i,nx,ny,nz=sel[2]
                c=s[i]+s.basis[0]*nx+s.basis[1]*ny+s.basis[2]*nz
                i,nx,ny,nz=sel[3]
                d=s[i]+s.basis[0]*nx+s.basis[1]*ny+s.basis[2]*nz
                l=(d-c).length()
                self.l3_entry.set_text("%14.8f"%l)
                angle=(b-c).angle(d-c)*180.0/pi
                self.a3_entry.set_text("%+7.4f"%angle)
                try:
                    dihedral=(c-b).cross(a-b).angle((b-c).cross(d-c))*180.0/pi
                    self.d3_entry.set_text("%+7.4f"%dihedral)
                except:
                    self.d3_entry.set_text("")
            except:
                msg().exception()
                self.l3_entry.set_text("")
                self.a3_entry.set_text("")
                self.d3_entry.set_text("")
        else:
            self.l3_entry.set_text("")
            self.a3_entry.set_text("")
            self.d3_entry.set_text("")