Esempio n. 1
0
    def read_xyzwv(cls, filename_full, gf_type=None):

        npoints_re = re.compile(r'' + "^\s*(\d+)\s*$" + '', re.IGNORECASE)
        xyzwv_re = re.compile(r'' + "^\s*(-?[0-9a-zA-Z+-.]+)\s+(-?[0-9a-zA-Z+-.]+)\s+(-?[0-9a-zA-Z+-.]+)\s+(-?[0-9a-zA-Z+-.]+)\s+(-?[0-9a-zA-Z+-.]+)" + '', re.IGNORECASE)

        i = 0
        with open(filename_full) as f:
            for line in f:
                if npoints_re.match(line):
                    npoints = numpy.int(npoints_re.match(line).group(1))
                    v = numpy.zeros((npoints,))
                    xyz = numpy.zeros((npoints, 3))
                    w = numpy.zeros((npoints,))

                if xyzwv_re.match(line):
                    xyz[i, :] = [xyzwv_re.match(line).group(1),
                                 xyzwv_re.match(line).group(2),
                                 xyzwv_re.match(line).group(3)]
                    w[i] = xyzwv_re.match(line).group(4)
                    v[i] = xyzwv_re.match(line).group(5)

                    i = i + 1

        grid = Grids.customgrid(None, xyz, w)

        import hashlib
        m = hashlib.md5()
        m.update("Gridfunction read from file:")
        m.update(os.path.abspath(filename_full))

        gf = GridFunctionFactory.newGridFunction(grid, v, checksum=m.digest(), gf_type=gf_type)

        return gf
Esempio n. 2
0
    def read_xyzw(filename_full):

        npoints_re = re.compile(r"^\s*(\d+)\s*$", re.IGNORECASE)
        xyzw_re = re.compile(
            r"^\s*(-?[0-9a-zA-Z+-.]+)\s+(-?[0-9a-zA-Z+-.]+)" +
            r"\s+(-?[0-9a-zA-Z+-.]+)\s+(-?[0-9a-zA-Z+-.]+)", re.IGNORECASE)

        i = 0
        with open(filename_full) as f:
            for line in f:
                if npoints_re.match(line):
                    npoints = numpy.int(npoints_re.match(line).group(1))
                    v = numpy.zeros((npoints, ))
                    xyz = numpy.zeros((npoints, 3))
                    w = numpy.zeros((npoints, ))

                if xyzw_re.match(line):
                    xyz[i, :] = [
                        xyzw_re.match(line).group(1),
                        xyzw_re.match(line).group(2),
                        xyzw_re.match(line).group(3)
                    ]
                    w[i] = xyzw_re.match(line).group(4)

                    i = i + 1

        grid = Grids.customgrid(None, xyz, w)
        return grid
Esempio n. 3
0
    def _make_gfs_from_numpy(filename_full, grid_xyzw, elpot, nucpot, rho,
                             rhod, rhodd):
        grid = Grids.customgrid(None, numpy.ascontiguousarray(grid_xyzw[:,
                                                                        0:3]),
                                numpy.ascontiguousarray(grid_xyzw[:, 3]))

        import hashlib
        m = hashlib.md5()
        m.update("Electrostatic potential read from file:")
        m.update(os.path.abspath(filename_full))

        pot_gf = GridFunctionFactory.newGridFunction(grid,
                                                     elpot,
                                                     checksum=m.digest(),
                                                     gf_type="potential")

        if nucpot is not None:
            m = hashlib.md5()
            m.update("Nuclear potential read from file:")
            m.update(os.path.abspath(filename_full))

            nucpot_gf = GridFunctionFactory.newGridFunction(
                grid, nucpot, checksum=m.digest(), gf_type="potential")
        else:
            nucpot_gf = None

        m = hashlib.md5()
        m.update("Density read from file:")
        m.update(filename_full)

        dens_gf = GridFunctionFactory.newGridFunction(grid,
                                                      rho,
                                                      checksum=m.digest(),
                                                      gf_type="density")

        m = hashlib.md5()
        m.update("Density gradient read from file:")
        m.update(filename_full)

        densgrad = GridFunctionFactory.newGridFunction(grid,
                                                       rhod,
                                                       checksum=m.digest())

        m = hashlib.md5()
        m.update("Density Hessian read from file:")
        m.update(filename_full)

        denshess = GridFunctionFactory.newGridFunction(grid,
                                                       rhodd,
                                                       checksum=m.digest())

        rho_gf = GridFunctionContainer([dens_gf, densgrad, denshess])

        return grid, pot_gf, nucpot_gf, rho_gf
Esempio n. 4
0
    def read_density_elpot_xyzwv(cls, filename_full):
        """
        FIXME: This needs a docstring explaining the file format!
        """

        npoints_re = re.compile(r'' + "^\s*(\d+)\s+\d" + '', re.IGNORECASE)
        density_re = re.compile(r'' + "^\s*(-?[0-9a-zA-Z+-.]+)\s+(-?[0-9a-zA-Z+-.]+)\s+(-?[0-9a-zA-Z+-.]+)\s+(-?[0-9a-zA-Z+-.]+)\s+(-?[0-9a-zA-Z+-.]+)\s+(-?[0-9a-zA-Z+-.]+)\s+(-?[0-9a-zA-Z+-.]+)\s+(-?[0-9a-zA-Z+-.]+)\s+(-?[0-9a-zA-Z+-.]+)\s+(-?[0-9a-zA-Z+-.]+)" + '', re.IGNORECASE)
        ngngnn_re = re.compile(r'' + "^\s*(-?[0-9a-zA-Z+-.]+)\s+(-?[0-9a-zA-Z+-.]+)\s+(-?[0-9a-zA-Z+-.]+)\s+(-?[0-9a-zA-Z+-.]+)\s+(-?[0-9a-zA-Z+-.]+)\s+(-?[0-9a-zA-Z+-.]+)\s+(-?[0-9a-zA-Z+-.]+)\s+(-?[0-9a-zA-Z+-.]+)\s+(-?[0-9a-zA-Z+-.]+)\s+(-?[0-9a-zA-Z+-.]+)\s+(-?[0-9a-zA-Z+-.]+)\s+(-?[0-9a-zA-Z+-.]+)\s+(-?[0-9a-zA-Z+-.]+)\s+(-?[0-9a-zA-Z+-.]+)\s+(-?[0-9a-zA-Z+-.]+)\s+(-?[0-9a-zA-Z+-.]+)" + '', re.IGNORECASE)

        i = 0
        with open(filename_full) as f:
            for line in f:
                if npoints_re.match(line):
                    npoints = numpy.int(npoints_re.match(line).group(1))
                    rho = numpy.zeros((npoints, 10))
                    elpot = numpy.zeros((npoints))
                    grid_xyzw = numpy.zeros((npoints, 4))
                if density_re.match(line):
                    # leaving space for the hessian of the density, force zeros for those
                    rho[i, :] = [density_re.match(line).group(7),
                                 density_re.match(line).group(8),
                                 density_re.match(line).group(9),
                                 density_re.match(line).group(10),
                                 0, 0, 0, 0, 0, 0]
                    elpot[i] = density_re.match(line).group(5)
                    elpot[i] += float(density_re.match(line).group(6))
                    grid_xyzw[i, :] = [density_re.match(line).group(1),
                                       density_re.match(line).group(2),
                                       density_re.match(line).group(3),
                                       density_re.match(line).group(4)]
                    i = i + 1
                elif ngngnn_re.match(line):
                    rho[i, :] = [density_re.match(line).group(7),
                                 density_re.match(line).group(8),
                                 density_re.match(line).group(9),
                                 density_re.match(line).group(10),
                                 density_re.match(line).group(11),
                                 density_re.match(line).group(12),
                                 density_re.match(line).group(13),
                                 density_re.match(line).group(14),
                                 density_re.match(line).group(15),
                                 density_re.match(line).group(16)]
                    elpot[i] = density_re.match(line).group(5)
                    elpot[i] += float(density_re.match(line).group(6))
                    grid_xyzw[i, :] = [density_re.match(line).group(1),
                                       density_re.match(line).group(2),
                                       density_re.match(line).group(3),
                                       density_re.match(line).group(4)]
                    i = i + 1

        grid = Grids.customgrid(None, numpy.ascontiguousarray(grid_xyzw[:, 0:3]),
                                numpy.ascontiguousarray(grid_xyzw[:, 3]))

        import hashlib
        m = hashlib.md5()
        m.update("Electrostatic potential read from file:")
        m.update(os.path.abspath(filename_full))

        pot_gf = GridFunctionFactory.newGridFunction(grid, elpot, checksum=m.digest(),
                                                     gf_type="potential")

        m = hashlib.md5()
        m.update("Density read from file:")
        m.update(filename_full)

        dens_gf = GridFunctionFactory.newGridFunction(grid, numpy.ascontiguousarray(rho[:, 0]),
                                                      checksum=m.digest(), gf_type="density")

        m = hashlib.md5()
        m.update("Density gradient read from file:")
        m.update(filename_full)

        densgrad = GridFunctionFactory.newGridFunction(grid, numpy.ascontiguousarray(rho[:, 1:4]),
                                                       checksum=m.digest())

        m = hashlib.md5()
        m.update("Density Hessian read from file:")
        m.update(filename_full)

        denshess = GridFunctionFactory.newGridFunction(grid, numpy.ascontiguousarray(rho[:, 4:10]),
                                                       checksum=m.digest())

        rho_gf = GridFunctionContainer([dens_gf, densgrad, denshess])

        return grid, pot_gf, rho_gf
Esempio n. 5
0
    def read_xml(filename_full):
        xyzw = read_xmldataset_to_numpy(filename_full, ['gridpoints'])

        grid = Grids.customgrid(None, xyzw[:, 0:3], xyzw[:, 3])
        return grid