Пример #1
0
def get_snap_site_features(d):
    feature = []
    data_filename = "lammps_snap.data"
    input_template = "lammps_snap_template.in"
    input_filename = "lammps_snap.in"
    dump_filename =  "dump.sna"
    log_filename = "log.lammps"

    sbp.check_call(["rm", "-f", input_filename])
    sbp.check_call(["rm", "-f", data_filename])    
    sbp.check_call(["rm", "-f", dump_filename])
    sbp.check_call(["rm", "-f", log_filename])

    structure = Structure.from_dict(d["structure"])
    feature.append(structure[d["absorbing_atom"]].specie.number)
    try:
        mol = Molecule.from_dict(d["cluster"])
    except TypeError:
        atoms = Atoms(structure, d["absorbing_atom"], 10.0)
        mol = atoms.cluster
    logger.info(mol.formula)
    lmp_data = LammpsData.from_structure(mol, [[0,25], [0,25],[0,25]], translate=False)    

    lmp_data.write_file(data_filename)
    el_sorted = sorted(mol.composition, key=lambda x:x.atomic_mass)
    cutoff = ""
    weight = ""
    for i, e in enumerate(el_sorted):
        cutoff += " {}".format(float(e.atomic_radius))
        weight += " {}".format(1.0)
        settings = {
            'data_file': data_filename,
            'rcutfac': 1.4, 
            'rfac0': 0.993630,
            'twojmax': 6.0,
            'cutoff': cutoff,
            'weight': weight,
            'dump_file': dump_filename
        }
    lmp_in = LammpsInput.from_file(input_template, settings)
    lmp_in.write_file(input_filename)
    #try:
    logger.info("Running LAMMPS ... ")
    exit_code = sbp.check_call(["./lmp_serial", "-in", input_filename])
    if exit_code != 0:
        logger.error("lammps run failed")
        raise RuntimeError("lammps run failed")                
    logger.info("Processing LAMMPS outputs ... ")
    lmp_run = LammpsRun(data_filename, dump_filename, log_filename)
    t = list(lmp_run.trajectory[0])
    try:
        assert np.linalg.norm(t[2:5]) <= 1e-6
    except AssertionError:
        logger.info("xyz: {}".format(t[2:5]))
        logger.error("assertion failed: first one not at origin")
        raise
    logger.info("# bispectrum coeffs: {}".format(len(t[5:])))
    feature.extend(t[5:])
    return feature
Пример #2
0
 def test_get_string(self):
     header = Header.from_string(header_string)
     struc = header.struct
     central_atom = 'O'
     a = Atoms(struc, central_atom, radius=10.)
     atoms = str(a)
     self.assertEqual(atoms.splitlines()[3].split()[4], central_atom,
                      "failed to create ATOMS string")
Пример #3
0
    def atoms(self):
        """
        absorber + the rest

        Returns:
            Atoms
        """
        return Atoms(self.structure, self.absorbing_atom, self.radius)
Пример #4
0
 def test_as_dict_and_from_dict(self):
     file_name = os.path.join(test_dir, 'HEADER')
     header = Header.from_file(file_name)
     struct = header.struct
     atoms = Atoms(struct, 'O', radius=10.)
     d = atoms.as_dict()
     atoms2 = Atoms.from_dict(d)
     self.assertEqual(str(atoms), str(atoms2),
                      "Atoms failed to and from dict test")
Пример #5
0
 def test_as_dict_and_from_dict(self):
     file_name = os.path.join(PymatgenTest.TEST_FILES_DIR, "HEADER")
     header = Header.from_file(file_name)
     struct = header.struct
     atoms = Atoms(struct, "O", radius=10.0)
     d = atoms.as_dict()
     atoms2 = Atoms.from_dict(d)
     self.assertEqual(str(atoms), str(atoms2),
                      "Atoms failed to and from dict test")
Пример #6
0
    def from_directory(input_dir):
        """
        Read in a set of FEFF input files from a directory, which is
        useful when existing FEFF input needs some adjustment.
        """
        sub_d = {}
        for fname, ftype in [("HEADER", Header), ("PARAMETERS", Tags)]:
            fullzpath = zpath(os.path.join(input_dir, fname))
            sub_d[fname.lower()] = ftype.from_file(fullzpath)

        # Generation of FEFFDict set requires absorbing atom, need to search
        # the index of absorption atom in the structure according to the
        # distance matrix and shell species information contained in feff.inp

        absorber_index = []
        radius = None
        feffinp = zpath(os.path.join(input_dir, 'feff.inp'))

        if "RECIPROCAL" not in sub_d["parameters"]:
            input_atoms = Atoms.cluster_from_file(feffinp)
            shell_species = np.array([x.species_string for x in input_atoms])

            # First row of distance matrix represents the distance from the absorber to
            # the rest atoms
            distance_matrix = input_atoms.distance_matrix[0, :]

            # Get radius value
            from math import ceil
            radius = int(ceil(input_atoms.get_distance(input_atoms.index(input_atoms[0]),
                                                       input_atoms.index(input_atoms[-1]))))

            for site_index, site in enumerate(sub_d['header'].struct):

                if site.specie == input_atoms[0].specie:
                    site_atoms = Atoms(sub_d['header'].struct, absorbing_atom=site_index,
                                       radius=radius)
                    site_distance = np.array(site_atoms.get_lines())[:, 5].astype(np.float64)
                    site_shell_species = np.array(site_atoms.get_lines())[:, 4]
                    shell_overlap = min(shell_species.shape[0], site_shell_species.shape[0])

                    if np.allclose(distance_matrix[:shell_overlap], site_distance[:shell_overlap]) and \
                            np.all(site_shell_species[:shell_overlap] == shell_species[:shell_overlap]):
                        absorber_index.append(site_index)

        if "RECIPROCAL" in sub_d["parameters"]:
            absorber_index = sub_d["parameters"]["TARGET"]
            absorber_index[0] = int(absorber_index[0]) - 1

        # Generate the input set
        if 'XANES' in sub_d["parameters"]:
            CONFIG = loadfn(os.path.join(MODULE_DIR, "MPXANESSet.yaml"))
            if radius is None:
                radius = 10
            return FEFFDictSet(absorber_index[0], sub_d['header'].struct, radius=radius,
                               config_dict=CONFIG, edge=sub_d["parameters"]["EDGE"],
                               nkpts=1000, user_tag_settings=sub_d["parameters"])
Пример #7
0
 def test_cluster_from_file(self):
     r = CifParser(os.path.join(test_dir, "CoO19128.cif"))
     structure = r.get_structures()[0]
     atoms = Atoms(structure, "O", 10.0)
     atoms.write_file("ATOMS_test")
     mol_1 = Atoms.cluster_from_file("ATOMS_test")
     mol_2 = Atoms.cluster_from_file(os.path.join(test_dir, "ATOMS"))
     self.assertEqual(mol_1.formula, mol_2.formula)
     self.assertEqual(len(mol_1), len(mol_2))
     os.remove("ATOMS_test")
Пример #8
0
 def test_absorbing_atom(self):
     atoms_1 = Atoms(self.structure, 0, 10.0)
     atoms_2 = Atoms(self.structure, 2, 10.0)
     self.assertEqual(atoms_1.absorbing_atom, "Co")
     self.assertEqual(atoms_2.absorbing_atom, "O")
Пример #9
0
 def setUpClass(cls):
     r = CifParser(os.path.join(test_dir, "CoO19128.cif"))
     cls.structure = r.get_structures()[0]
     cls.atoms = Atoms(cls.structure, "O", 10.0)
Пример #10
0
 def setUp(self):
     feo = Structure.from_dict(
         {'lattice': {'a': 3.3960486211791285,
                   'alpha': 91.45136142952781,
                   'b': 3.410591877060444,
                   'beta': 89.27127081348024,
                   'c': 10.71766796897646,
                   'gamma': 120.14175587658389,
                   'matrix': [[3.39597035, -0.00828486, 0.02151698],
                    [-1.70515997, 2.9534242, -0.04303398],
                    [0.06812465, -0.11799566, 10.71680189]],
                   'volume': 107.31813123502585},
                  'sites': [{'abc': [0.33497754, 0.66579918, 0.97174225],
                    'label': 'Fe',
                    'properties': {'coordination_no': 4,
                     'forces': [-0.01537896, -0.08731049, 0.04884326]},
                    'species': [{'element': 'Fe', 'occu': 1}],
                    'xyz': [0.06847928463257683, 1.8489508003914767, 10.392524897825345]},
                   {'abc': [0.99661905, 0.00734083, 0.22366433],
                    'label': 'Fe',
                    'properties': {'coordination_no': 4,
                     'forces': [-0.01685376, -0.01008504, 0.05451912]},
                    'species': [{'element': 'Fe', 'occu': 1}],
                    'xyz': [3.387208508781326, -0.0129676845693048, 2.4180946415046494]},
                   {'abc': [0.00338095, 0.01072178, 0.72366433],
                    'label': 'Fe',
                    'properties': {'coordination_no': 4,
                     'forces': [0.01716078, 0.00955327, 0.05451912]},
                    'species': [{'element': 'Fe', 'occu': 1}],
                    'xyz': [0.04249863509042039, -0.053751296415148794, 7.754978606437029]},
                   {'abc': [0.66502246, 0.33082164, 0.47174225],
                    'label': 'Fe',
                    'properties': {'coordination_no': 4,
                     'forces': [0.08330257, -0.03033668, 0.04884326]},
                    'species': [{'element': 'Fe', 'occu': 1}],
                    'xyz': [1.7264300141777726, 0.9158834813430974, 5.055640939524896]},
                   {'abc': [0.33062914, 0.66733572, 0.77744897],
                    'label': 'O',
                    'properties': {'coordination_no': 4,
                     'forces': [-0.07726687, -0.00523346, -0.05206924]},
                    'species': [{'element': 'O', 'occu': 1}],
                    'xyz': [0.03785603896498114, 1.8764506445041333, 8.310162619639584]},
                   {'abc': [0.00312189, 0.99229908, 0.52714445],
                    'label': 'O',
                    'properties': {'coordination_no': 4,
                     'forces': [-0.06744419, 0.00047044, -0.05129314]},
                    'species': [{'element': 'O', 'occu': 1}],
                    'xyz': [-1.6455152924521734, 2.8684534947950637, 5.606667232944964]},
                   {'abc': [0.99687811, 0.98917618, 0.02714445],
                    'label': 'O',
                    'properties': {'coordination_no': 4,
                     'forces': [0.03331469, 0.05864361, -0.05129314]},
                    'species': [{'element': 'O', 'occu': 1}],
                    'xyz': [1.7005140848662161, 2.9099949452040543, 0.2697833114717219]},
                   {'abc': [0.66937086, 0.33670658, 0.27744897],
                    'label': 'O',
                    'properties': {'coordination_no': 4,
                     'forces': [0.04316575, 0.06429835, -0.05206924]},
                    'species': [{'element': 'O', 'occu': 1}],
                    'xyz': [1.7179261258365088, 0.9561539434765862, 2.9732786612521678]}]})
     atoms = Atoms(feo, 0, 10.0)
     self.paths = Paths(atoms, [[22, 16, 0], [250, 282, 250, 0]])
Пример #11
0
 def setUpClass(cls):
     r = CifParser(os.path.join(PymatgenTest.TEST_FILES_DIR,
                                "CoO19128.cif"))
     cls.structure = r.get_structures()[0]
     cls.atoms = Atoms(cls.structure, "O", 10.0)
Пример #12
0
 def init_atoms(self):
     self._atoms = Atoms(
         struct=self.structure,
         absorbing_atom=self.absorbing_atom,
         radius=self.cluster_size
     )
Пример #13
0
    )
    zno_structure = Structure.from_spacegroup(
        sg=186, lattice=zno_lattice_init,
        species=[Element('Zn'), Element('O')],
        coords=[
            [1 / 3, 2 / 3, 0.00000],
            [1 / 3, 2 / 3, 0.37780],
        ],
        coords_are_cartesian=False,
        tol=1e-9,
    )
    print(zno_structure)
    print(zno_structure.get_space_group_info())
    out_file_name = '/home/yugin/PycharmProjects/neurons/data/src/feff.inp.new2'
    file_name = '/home/yugin/PycharmProjects/neurons/data/src/feff.inp.old'
    atoms_obj = Atoms(zno_structure, 'O', 12)
    pprint(atoms_obj.struct.cart_coords)
    pprint(atoms_obj.get_lines())

    header_obj = Header(struct=zno_structure)
    pot_obj = Potential(zno_structure, 'O')


    tags_obj = Tags().from_file(filename=file_name)
    pprint(tags_obj.as_dict())

    pot_obj.pot_string_from_file(filename=file_name)
    pprint(pot_obj)
    atoms_obj.atoms_string_from_file(filename=file_name)
    pprint(atoms_obj.as_dict())