Esempio n. 1
0
    def readStructure(self, Id, cstructure=False):
        s = Structure()
        l = self.fetchone(
            """SELECT calc_id,scale,comment,a11,a12,a13,a21,a22,a23,a31,a32,a33,
          species FROM #STRUCT WHERE id=%d""" % (Id))
        (calc_id, scale, s.comment, s.basis[0][0], s.basis[0][1],
         s.basis[0][2], s.basis[1][0], s.basis[1][1], s.basis[1][2],
         s.basis[2][0], s.basis[2][1], s.basis[2][2], spec) = l

        s.scaling = [scale]
        s.setCartesian()

        l = self.fetchall(
            "SELECT specie,element,x,y,z FROM #STRUCTPOS WHERE structure_id=%d ORDER BY atomnumber"
            % (Id))
        for spec, element, x, y, z in l:
            i = s.appendAtom(spec, Vector(x, y, z))
            s.info.getRecordForAtom(i).element = str(element)

        l = self.fetchall(
            "SELECT x,y,z FROM #STRUCTCONSTRAINTS WHERE structure_id=%d ORDER BY atomnumber"
            % (Id))
        if len(l):
            s.setSelective()
            for i in range(len(l)):
                s.selective[i] = [int(l[i][0]), int(l[i][1]), int(l[i][2])]

        if cstructure:
            s = p4vasp.cStructure.Structure(s)

        return s
Esempio n. 2
0
    def storeStructure(self, s, step=None):
        calc_id = self.calc_id
        if calc_id is not None and step is not None:
            for l in self.fetchall(
                    "SELECT id FROM #STRUCT WHERE calc_id=%d AND step=%d" %
                (calc_id, step)):
                removeStructure(db, l[0])

        info = s.info

        if len(s.scaling) != 1:
            s.correctScaling()

        cmd = "%s, %s," % (von(calc_id), von(step))
        cmd += "%14.12f,'%s'," % (s.scaling[0], s.comment)
        cmd += """%14.12f,%14.12f,%14.12f,
        %14.12f,%14.12f,%14.12f,
        %14.12f,%14.12f,%14.12f,%d""" % (
            s.basis[0][0], s.basis[0][1], s.basis[0][2], s.basis[1][0],
            s.basis[1][1], s.basis[1][2], s.basis[2][0], s.basis[2][1],
            s.basis[2][2], s.types)

        Id = self.insertRecord(
            "#STRUCT", "id",
            "calc_id, step, scale,comment,a11,a12,a13,a21,a22,a23,a31,a32,a33,species",
            cmd)

        if s.isSelective():
            sel = s.selective
            for i in range(len(sel)):
                self.exe(
                    """INSERT INTO #STRUCTCONSTRAINTS (structure_id,calc_id,atomnumber,x,y,z)
                VALUES (%d,%s,%d,%d,%d,%d)""" %
                    (Id, von(calc_id), i, sel[i][0], sel[i][1], sel[i][2]))

        sc = Structure()
        sc.setStructure(s)
        sc.setCartesian()

        for i in range(len(s)):
            si = s.speciesIndex(i)

            self.exe(
                """INSERT INTO #STRUCTPOS (structure_id,calc_id,atomnumber,specie,element,x,y,z)
            VALUES (%d,%s,%d,%d,'%s',%14.12f,%14.12f,%14.12f)""" %
                (Id, von(calc_id), i, si, info[si].element, sc[i][0], sc[i][1],
                 sc[i][2]))
        self.commit()
        return Id