Example #1
0
    def on_copy_button_clicked_handler(self, *arg):
        try:
            v1 = float(self.vx_entry.get_text())
        except:
            msg().error("Wrong x-field in Vector.")
        try:
            v2 = float(self.vy_entry.get_text())
        except:
            msg().error("Wrong y-field in Vector.")
        try:
            v3 = float(self.vz_entry.get_text())
        except:
            msg().error("Wrong z-field in Vector.")
        v = Vector(v1, v2, v3)
        if self.system is not None:
            if self.system.INITIAL_STRUCTURE is not None:
                s = self.system.INITIAL_STRUCTURE
                s.setCarthesian()
                sel = Selection(self.group_entry.get_text(), s)
                l = []
                for i in sel.getAtoms():
                    if i >= 0 and i < len(s):
                        l.append((s.speciesIndex(i), s[i] + v))
                for i, v in l:
                    s.appendAtom(i, v)

                msg().status("OK")
                systemlist().notifySystemChanged()
            else:
                msg().error("No initial structure in the current system.")
        else:
            msg().error("No system selected.")
Example #2
0
    def rotate(self):
        try:
            v1 = float(eval(self.vx_entry.get_text()))
        except:
            msg().error("Invalid x-field in axis.")
        try:
            v2 = float(eval(self.vy_entry.get_text()))
        except:
            msg().error("Invalid y-field in axis.")
        try:
            v3 = float(eval(self.vz_entry.get_text()))
        except:
            msg().error("Invalid z-field in axis.")
        v = Vector(v1, v2, v3)

        try:
            o1 = float(eval(self.fromx_entry.get_text()))
        except:
            msg().error("Invalid x-field in center.")
        try:
            o2 = float(eval(self.fromy_entry.get_text()))
        except:
            msg().error("Invalid y-field in center.")
        try:
            o3 = float(eval(self.fromz_entry.get_text()))
        except:
            msg().error("Invalid z-field in center.")
        o = Vector(o1, o2, o3)

        try:
            a = float(eval(self.angle_entry.get_text()))
        except:
            msg().error("Invalid angle.")
        a *= pi / 180.0

        n = v.normal()
        if self.system is not None:
            if self.system.INITIAL_STRUCTURE is not None:
                s = self.system.INITIAL_STRUCTURE
                s.setCarthesian()
                sel = Selection(self.group_entry.get_text(), s)
                for i, nx, ny, nz in sel:
                    d = nx * s.basis[0] + ny * s.basis[1] + nz * s.basis[2]
                    if i >= 0 and i < len(s):
                        r = s[i] + d - o
                        s[i] = cos(a) * r + (
                            (n * r) *
                            (1 - cos(a))) * n + sin(a) * r.cross(n) + o - d

                msg().status("OK")
                systemlist().notifySystemChanged()
            else:
                msg().error("No initial structure in the current system.")
        else:
            msg().error("No system selected.")
Example #3
0
    def readVacGen(self):
        self.select_atoms = self.sel.getAtoms()

        #    print self.select_atoms
        #    selectedatoms=string.split(self.xml.get_widget("sel_entry").get_text())
        #    self.select_status=0
        #    self.select_atoms=[]
        #    try:
        #      for i in range(len(selectedatoms)):
        #        self.select_atoms.append(int(selectedatoms[i]))
        #        self.select_status=1
        #    except ValueError:
        #      self.select_status=0
        #      self.select_atoms=[]
        #    #else:
        #    print 'selected are:',selectedatoms

        system = self.system
        self.world[0].subtitle = ""
        if len(self.sel):
            if system is not None:
                s = system.INITIAL_STRUCTURE
            st = self.sel.encode(s)
            self.world[0].subtitle = "Selected atoms:%s" % st

        msg().status("VAC")
        yield 1
        if system is not None:
            name = system.current("NAME")
            if name is not None:
                self.world[0].subtitle = "(%s)" % name
            t0 = time.clock()
            natoms = None
            if self.multi:
                totalnumconfigs = 0
                systems = systemlist()
                for s in systems:
                    cs = s.CSTRUCTURE_SEQUENCE_L
                    if cs is not None:
                        totalnumconfigs += len(cs)
                        natoms = len(cs[0])  # number of atoms in single config

                try:
                    initconfigs = int(
                        self.xml.get_widget(
                            "init_entry").get_text())  # configs to be skipped
                except:
                    initconfigs = 0
                allcarts = zeros((totalnumconfigs - initconfigs, natoms, 3),
                                 Float)

                t1 = time.clock()
                indx = 0
                for si in range(len(systems)):
                    ss = systems[si].CSTRUCTURE_SEQUENCE_L
                    if ss is not None:
                        msg().message('t(parsing): %f' % (t1 - t0))
                        if initconfigs > (len(ss)):
                            initconfigs -= (len(ss))
                            continue

                        #if si!=0:initconfigs+=1
                        numconfigs = len(ss)  # total number of configs
                        for i in range(initconfigs, numconfigs):
                            if indx % 50 == 0:
                                msg().status(
                                    "Reading %s positions (%f s)" %
                                    (systems[si].NAME, time.clock() - t1))
                                msg().step(indx, len(allcarts))
                                yield 1
                            ss[i].setCarthesian()
                            ssi = map(array, ss[i])
                            allcarts[indx] = ssi  #ss[i] #.positions
                            indx += 1
                        msg().step(0, 1)
                        initconfigs = 0
            else:
                s = system
                ss = s.CSTRUCTURE_SEQUENCE_L
                t1 = time.clock()
                msg().message('t(parsing): %f' % (t1 - t0))

                numconfigs = len(ss)  # total number of configs
                natoms = len(ss[0])  # number of atoms in single config
                try:
                    initconfigs = int(
                        self.xml.get_widget(
                            "init_entry").get_text())  # configs to be skipped
                except:
                    initconfigs = 0
                allcarts = zeros((numconfigs - initconfigs, natoms, 3), Float)
                for i in range(initconfigs, numconfigs):
                    indx = i - initconfigs
                    if indx % 50 == 0:
                        msg().status("Reading positions (%f s)" %
                                     (time.clock() - t1))
                        msg().step(indx, numconfigs - initconfigs)
                        yield 1
                    ss[i].setCarthesian()
                    allcarts[indx] = ss[i]  #.positions
                msg().step(0, 1)
            velocities = zeros((len(allcarts) - 2, len(allcarts[0]), 3), Float)
            msg().status("Calculating velocities")
            yield 1
            if len(self.select_atoms) > 0:
                pattern = zeros((len(allcarts[0]), 3))
                for i in self.select_atoms:
                    pattern[i] = 1
            else:
                pattern = ones((len(allcarts[0]), 3))
            allcarts = allcarts * pattern
            for i in range(1, len(allcarts) - 1):
                velocities[i - 1] = (allcarts[i + 1] - allcarts[i - 1]
                                     )  #*pattern
                if i % 100 == 0:
                    msg().step(i, len(allcarts) - 1)
                    yield 1

            msg().step(0, 1)
            t2 = time.clock()
            msg().message('t(velocities): %f' % (t2 - t1))
            msg().status('Calculating VAC')
            yield 1
            scheduleFirst(self.giveVacGen(velocities))  ###???????
            yield 1
            t3 = time.clock()
            msg().message('t(vac):%f' % (t3 - t2))
        else:
            self.vac = []
        msg().step(0, 1)
        msg().status("OK")
        self.xml.get_widget("win_lab").set_sensitive(True)
        self.xml.get_widget("winopt").set_sensitive(True)
        self.xml.get_widget("filter_button").set_sensitive(True)
        self.xml.get_widget("fft_button").set_sensitive(True)
        self.freq = []
        self.updateGraph()
Example #4
0
    def changePositions(self):
        sel=self.sel
        if len(sel)==0:
            msg().status("No atoms selected.")
            return
        if len(sel)>1:
            try:
                l1=float(eval(self.l1_entry.get_text()))
                print "l1",l1
            except:
                msg().error("Error parsing length 1 in sub-Z-matrix")
                return

        if len(sel)>2:
            try:
                l2=float(eval(self.l2_entry.get_text()))
                print "l2",l2
            except:
                msg().error("Error parsing length 2 in sub-Z-matrix")
                return
            try:
                a2=float(eval(self.a2_entry.get_text()))
                print "a2",a2
            except:
                msg().error("Error parsing angle 1 in sub-Z-matrix")
                return

        if len(sel)>3:
            try:
                l3=float(eval(self.l3_entry.get_text()))
                print "l3",l3
            except:
                msg().error("Error parsing length 3 in sub-Z-matrix")
                return
            try:
                a3=float(eval(self.a3_entry.get_text()))
                print "a3",a3
            except:
                msg().error("Error parsing angle 2 in sub-Z-matrix")
                return
            try:
                d3=float(eval(self.d3_entry.get_text()))
                print "d3",d3
            except:
                msg().error("Error parsing dihedral angle in sub-Z-matrix")
                return

        s=self.system.INITIAL_STRUCTURE
        if s is not None:
            s.setCarthesian()
        else:
            msg().error("No initial structure available.")

        if len(sel)>=2:
            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
            dv=v2-v1
            l=(v1-v2).length()
            if l!=0.0:
                s[i]=v1+(l1/l)*dv-s.basis[0]*nx-s.basis[1]*ny-s.basis[2]*nz
            else:
                msg().status("Atoms have the same position, moving in X-direction")
                s[i]=v1+Vector(l1,0.0,0.0)-s.basis[0]*nx-s.basis[1]*ny-s.basis[2]*nz

        if len(sel)>=3:
            i0,nx0,ny0,nz0=sel[0]
            a=s[i0]+s.basis[0]*nx0+s.basis[1]*ny0+s.basis[2]*nz0
            i1,nx1,ny1,nz1=sel[1]
            b=s[i1]+s.basis[0]*nx1+s.basis[1]*ny1+s.basis[2]*nz1
            i2,nx2,ny2,nz2=sel[2]
            c=s[i2]+s.basis[0]*nx2+s.basis[1]*ny2+s.basis[2]*nz2

            l=(a-b).length()
            dv=(b-a)
            angle=(a-b).angle(c-b)*180.0/pi
            if l==0.0:
                msg().status("First two atoms have the same position, moving in X-direction")
                dv=Vector(1.0,0.0,0.0)
                l=1.0

            try:
                n1=(c-b).cross(a-b).normal()
            except:
                msg().status("First three atoms do not define a plane, using Z-axis for rotation.")
                try:
                    n1=Vector(0.0,-dv[2],dv[1]).normal()
                except:
                    n1=Vector(0.0,0.0,1.0)

            s[i2]=rot(b,n1,b-(l2/l)*dv,a2*pi/180.0)-s.basis[0]*nx2-s.basis[1]*ny2-s.basis[2]*nz2

        if len(sel)>=4:
            i0,nx0,ny0,nz0=sel[0]
            a=s[i0]+s.basis[0]*nx0+s.basis[1]*ny0+s.basis[2]*nz0
            i1,nx1,ny1,nz1=sel[1]
            b=s[i1]+s.basis[0]*nx1+s.basis[1]*ny1+s.basis[2]*nz1
            i2,nx2,ny2,nz2=sel[2]
            c=s[i2]+s.basis[0]*nx2+s.basis[1]*ny2+s.basis[2]*nz2
            i3,nx3,ny3,nz3=sel[3]
            d=s[i3]+s.basis[0]*nx3+s.basis[1]*ny3+s.basis[2]*nz3


            try:
                n1=(c-b).cross(a-b).normal()
            except:
                msg().status("First three atoms do not define a plane, using Z-axis.")
                try:
                    n1=Vector(0.0,-dv[2],dv[1]).normal()
                except:
                    n1=Vector(0.0,0.0,1.0)

            l=(b-c).length()
            dv=(c-b)
            angle=(b-c).angle(d-c)*180.0/pi
            if l==0.0:
                msg().status("Second and third have the same position, using X-direction")
                dv=Vector(1.0,0.0,0.0)
                l=1.0


            newd=rot(c,n1,c-(l3/l)*dv,a3*pi/180.0)
            s[i3]=rot(c,c-b,newd,(180+d3)*pi/180.0)-s.basis[0]*nx3-s.basis[1]*ny3-s.basis[2]*nz3


        systemlist().notifySystemChanged()