Exemple #1
0
def running(temp, pre, crt):
    # -- Run AIMD at (run00, run01, ...)
    # -- First step is heat-up.
    total_try = 1
    #pre_dir = ("run%2d" % pre).replace(" ", "0")
    #crt_dir = ("run%2d" % crt).replace(" ", "0")
    pre_dir = ("run%03d" % pre)
    crt_dir = ("run%03d" % crt)
    # -- initiating
    if crt == 0:
        structure = IStructure.from_file("../" + structure_filename)
        crt_nsw = heating_nsw
        user_incar["SMASS"] = -1
        inputset = MITMDSet(structure,
                            100.0,
                            float(temp),
                            heating_nsw,
                            user_incar_settings=user_incar)
        inputset.write_input(crt_dir)
    # -- run
    else:
        run = Vasprun("%s/vasprun.xml.gz" % pre_dir,
                      parse_dos=False,
                      parse_eigen=False)
        structure = run.final_structure
        crt_nsw = nsw
        #structure = IStructure.from_file("%s/CONTCAR" % pre_dir)
        user_incar["SMASS"] = 0
        inputset = MITMDSet(structure,
                            float(temp),
                            float(temp),
                            nsw,
                            user_incar_settings=user_incar)
        inputset.write_input(crt_dir)
        os.system("cp %s/WAVECAR %s" % (pre_dir, crt_dir))
    os.chdir(crt_dir)
    os.system("mpirun -np $NSLOTS %s < /dev/null > vasp.out" % vasp)
    time.sleep(5)
    os.system("gzip OUTCAR vasprun.xml")
    os.system("rm -rf DOSCAR XDATCAR")
    write_log("try: %d" % total_try)
    properly_terminated = terminated_check(crt_nsw)
    while not properly_terminated:
        total_try += 1
        os.system("mpirun -np $NSLOTS %s < /dev/null > vasp.out" % vasp)
        time.sleep(5)
        os.system("gzip OUTCAR vasprun.xml")
        os.system("rm -rf DOSCAR XDATCAR")
        write_log("try: %d" % total_try)
        properly_terminated = terminated_check(crt_nsw)
    os.system("touch vasp.done")
    os.chdir("../")
    os.system("rm -rf %s/WAVECAR" %
              pre_dir)  # remove WAVECAR in previous dir to reduce storage
    def __init__(self, filename, grid_size=1):
        structure = IStructure.from_file(filename)
        self.grid_size = grid_size

        self.sites = structure.sites
        self.all_species = [site.specie.number for site in self.sites]
        self.all_coords = [site.coords for site in self.sites]

        lattice = structure.lattice
        a, b, c = lattice.a, lattice.b, lattice.c
        self.grid_a = self.get_grid_length(a, self.grid_size)
        self.grid_b = self.get_grid_length(b, self.grid_size)
        self.grid_c = self.get_grid_length(c, self.grid_size)

        # total_atom_info = get_cgcnn_atom_info()
        total_atom_info = atomic_info()
        empty_info = np.full(total_atom_info[0].shape, -1)
        empty_info = np.array([empty_info])
        self.total_atom_info = np.concatenate((empty_info, total_atom_info),
                                              axis=0)
Exemple #3
0
def get_data(normalize_y, sample_size):
    radius = 3
    max_neighbor_num = 10
    training = 0.9
    test = 0.1

    df = pd.read_csv("./Data/metal-alloy-db.v2/00Total_DB.csv")
    # df = df.sample(n=len(df))
    df = df.sample(n=sample_size)

    cifs = "./Data/metal-alloy-db.v2/" + df['DBname'] + ".cif"
    structures = [IStructure.from_file(cif) for cif in cifs]
    encoded_structures = [
        structure_encoder(structure, radius, max_neighbor_num)
        for structure in structures
    ]
    x_data = np.array(encoded_structures)

    formation_energy = df['FormationEnergy']
    if normalize_y:
        mean = formation_energy.mean()
        std = formation_energy.std()
        norm_form_energy = (df['FormationEnergy'] - mean) / std

        def norm_back(val, mean, std):
            return val * std + mean

        y_data = [[val] for val in norm_form_energy]
    else:
        y_data = [[val] for val in formation_energy]
    y_data = np.array(y_data)

    total = len(df)
    train = int(float(total) * training)
    test = int(float(total) * test)
    x_train = x_data[:train]
    y_train = y_data[:train]
    x_test = x_data[train:train + test]
    y_test = y_data[train:train + test]

    return x_train, y_train, x_test, y_test
Exemple #4
0
    return batch_x, batch_y


if __name__ == "__main__":
    radius = 3
    max_neighbor_num = 10
    training = 0.9
    test = 0.1

    df = pd.read_csv("./Data/metal-alloy-db.v1/00Total_DB.csv")
    # df = df.sample(n=len(df))
    df = df.sample(n=500)

    cifs = "./Data/metal-alloy-db.v1/" + df['DBname'] + ".cif"
    structures = [IStructure.from_file(cif) for cif in cifs]

    encoded_structures = [structure_encoder(structure, radius, max_neighbor_num) for structure in structures]
    x_data = np.array(encoded_structures)
    x_data = np.expand_dims(x_data, axis=4)

    formation_energy = df['FormationEnergy']
    y_normalization = False
    if y_normalization:
        mean = formation_energy.mean()
        std = formation_energy.std()
        norm_form_energy = (df['FormationEnergy'] - mean) / std

        def norm_back(val, mean, std):
            return val * std + mean
        y_data = [[val] for val in norm_form_energy]
Exemple #5
0

def check_converged(crt_step, RSD, ASD):
    converged = False
    if crt_step >= min_step:
        if RSD <= min_RSD:
            if ASD <= min_ASD:
                converged = True
    if crt_step >= 300:
        converged = True

    return converged


if __name__ == "__main__":
    structure = IStructure.from_file(structure_filename)
    # -- Find neighboring specie distance
    sites = structure.sites
    specie_sites = [s for s in sites if str(s.specie) == specie]
    distance = []
    for specie_site in specie_sites:
        nbrs = structure.get_neighbors(specie_site, 5)
        nbrs = [nbr for nbr in nbrs if str(nbr[0].specie) == specie]
        for nbr in nbrs:
            distance.append(nbr[1])
    distance = np.array(distance)
    avg_specie_distance = distance.mean()

    working_dir = "%dK" % temp
    mkdir(working_dir)
    os.chdir(working_dir)
Created on September 10, 2013
@author: Qimin
'''
import sys
import pymatgen
from math import *
from pymatgen.symmetry.finder import SpacegroupAnalyzer
from pymatgen.core.structure import IStructure

file = str(sys.argv[1])
spacegroup = str(sys.argv[2])
max = float(sys.argv[3])
min = float(sys.argv[4])
iter = float(sys.argv[5])

s = IStructure.from_file(file)

def getLowSymPrec(s,max,min,spacegroup,iter):
    SG = str(spacegroup)
    if SG!=str(SpacegroupAnalyzer(s,symprec=max).get_spacegroup_number()):
        print "Not reasonable spacegroup or max too large"
        return -1
    elif SG==str(SpacegroupAnalyzer(s,symprec=min).get_spacegroup_number()):
        return min
    else:
        upperbound = max
        lowerbound = min
        i=0
        while i<iter:
            trial = 10**((log(upperbound,10)+log(lowerbound,10))/2)
            if SG==str(SpacegroupAnalyzer(s,symprec=trial).get_spacegroup_number()):
def find_unique_structures(base_crystal_path, directory):
    """
    DESCRIPTION: Given a base crystal structure along with a directory containing CIF structures, determine how many unique configurations are in the directory,
                 and assign a configuration ID number to each CIF structure in the directory. Results can be seen in the outputted unique.csv file. The function
                 uses the base crystal structure provided to find the space group and associated symmetry operations, which are then used to see whether the CIF
                 structures in the directory are equivalent. 
                 
    PARAMETERS:
        base_crystal_path: string
            The path to the base crystal CIF structure. Note that this structure should contain the space group that you want to check all other structures to.
            If the symmetry of this structure is incorrect, you will get unexpected results. 
        directory: string
            The path to the directory containing the CIF structures to compare. Note that this function assumes that the CIF names are all prefixed by a dash
            and followed by an interger, ie "LiCoO2-1", "LiCoO2-2", "LiCoO2-3"..., ect.
    RETURNS: None
    """
    # convert all files (they should all be cif files) in the directory into Structures and place them into a list
    cif_file_names = [
        os.path.splitext(os.path.basename(path))[0]
        for path in os.listdir(directory) if path.endswith('.cif')
    ]
    cif_files = [
        directory + path for path in os.listdir(directory)
        if path.endswith('.cif')
    ]
    cif_files = sorted(cif_files,
                       key=lambda x: int(x.split("-")[-1].replace(".cif", "")))
    cif_file_names = sorted(cif_file_names,
                            key=lambda x: int(x.split("-")[-1]))
    structures = [IStructure.from_file(path) for path in cif_files]
    print(cif_file_names)
    # Get the base crystal structure
    base_crystal = IStructure.from_file(base_crystal_path)

    # Get the space group of the base crystal
    analyzer = SpacegroupAnalyzer(base_crystal)
    spacegroup = analyzer.get_space_group_operations()
    print(spacegroup)

    id = 1
    num_structures = len(structures)
    config_dict = {}
    unique_structs = []
    for i in range(num_structures):
        config1 = structures[i]
        unique_cif_name = cif_file_names[i]
        if not unique_cif_name in config_dict:
            config_dict[unique_cif_name] = id
            print("%s Unique Structures Found..." % (id))
            unique_structs.append(config1)
            id += 1
            for j in range(num_structures):
                cif_name = cif_file_names[j]
                config2 = structures[j]
                if not cif_name in config_dict:
                    isEquivalent = spacegroup.are_symmetrically_equivalent(
                        config1, config2)
                    if isEquivalent:
                        config_dict[cif_name] = config_dict[unique_cif_name]
    print("----------------------------------------------")
    print("%s Total Unique Structures Found" % (id - 1))
    print("----------------------------------------------")
    with open('unique.csv', 'w') as f:
        for key in config_dict.keys():
            f.write("%s,%s\n" % (key, config_dict[key]))
    crystal_name = os.path.splitext(os.path.basename(base_crystal_path))[0]
    directory_path = "{}-unique".format(crystal_name)
    if not os.path.isdir(directory_path):
        os.mkdir(directory_path)

    num_unique_structures = len(unique_structs)
    for i in range(num_unique_structures):
        config = unique_structs[i]
        #Save to CIF
        filename = crystal_name + '_ewald' + '_{}'.format(i + 1)
        w = CifWriter(config)
        w.write_file(directory_path + '/' + filename + '.cif')
        # print("Cif file saved to {}.cif".format(filename))

        #Save to POSCAR
        poscar = Poscar(config)
        poscar.write_file(directory_path + '/' + filename)
#ComputedEntry(composition: pymatgen.core.composition.Composition, energy: float, correction: float = 0.0, energy_adjustments: list = None, parameters: dict = None, data: dict = None, entry_id: object = None)
#IStructure.from_file('LiB-42129-4374-9-out.cif')
#ComputedStructureEntry(structure=IStructure.from_file('LiB-42129-4374-9-out.cif'),energy=1,entry_id='from castep for airss')


import os
current_dir = os.getcwd()

entries=[]
for filename in os.listdir(current_dir):
    if filename.endswith(".res"):
        print('loading ', filename)
        #read enthalpy, did not correct enthalpy for pressure
        f = open(filename, "r")
        enthalpy=f.readline().split()[4]
        f.close()
        #load structure and composition, cabal in airss is needed
        os.system("cabal res poscar < "+filename+" > POSCAR")
        entries.append(ComputedStructureEntry(structure=IStructure.from_file('POSCAR'), energy=float(enthalpy)))
        os.system("rm POSCAR")


#pd=PhaseDiagram(entries)
#pd.show()


#li_entries = [e for e in entries if e.composition.reduced_formula == "Li"]
#uli0 = min(li_entries, key=lambda e: e.energy_per_atom).energy_per_atom
#gpd=GrandPotentialPhaseDiagram(entries,chempots=)
Exemple #9
0
from pymatgen.core.structure import IStructure
from pymatgen.electronic_structure.bandstructure import BandStructure, BandStructureSymmLine, Kpoint

vasp = Vasprun(
    'vasprun.xml'
)  #,ionic_step_skip=1,ionic_step_offset=1,parse_dos=True,parse_eigen=True,occu_tol=1e-8)
efermi = vasp.efermi
eigenvals = vasp.eigenvalues
bs = vasp.get_band_structure(kpoints_filename='KPOINTS',
                             efermi=efermi,
                             line_mode=True)
#kpoints_modes = Kpoints_support_modes(3) #Line mode
kpoints = Kpoints.from_file('KPOINTS')
poscar = Poscar.from_file('POSCAR')
incar = Incar.from_file(('INCAR'))
struc = IStructure.from_file('POSCAR')
lattice = struc.lattice
labels = kpoints.labels
space_group = struc.get_space_group_info()
#coords = struc.frac_coords()
BS = BandStructure(kpoints.kpts, eigenvals, lattice, efermi,
                   structure=struc)  #kpoints.kpts
labels_dict = BS.labels_dict
BSSL = BandStructureSymmLine(kpoints.kpts,
                             eigenvals,
                             lattice,
                             efermi,
                             labels_dict,
                             structure=struc)
b = vasp.eigenvalue_band_properties
vbm = BS.get_vbm()
Exemple #10
0
    all_sites_atom_info = [atom_info[num - 1] for num in all_sites_atom_num]
    all_sites_atom_info = np.array(all_sites_atom_info)
    all_sites_atom_info = np.expand_dims(all_sites_atom_info, axis=1)
    all_sites_atom_info = np.tile(all_sites_atom_info,
                                  [1, max_neighbor_num, 1])

    neighbor_atom_info = []
    for each_neighbor in neighbor_atom_num:
        neighbor_atom_info.append(
            [atom_info[num - 1] for num in each_neighbor])
    neighbor_atom_info = np.array(neighbor_atom_info)

    features = (all_sites_atom_info, neighbor_atom_info,
                onehot_neighbor_distance)
    encoded_structure = np.concatenate(features, axis=2)

    # shape=   (num_sites)      (num_sites, max_neighbor_num)    (num_sites, max_neighbor_num, onehot_length)
    #   ex.    (8, 10, 47)      (8, 10, 47)                      (8, 10, 10)
    #return (all_sites_atom_info, neighbor_index, onehot_neighbor_distance)
    return encoded_structure


if __name__ == "__main__":
    radius = 3
    max_neighbor_num = 10
    cifs = ["./Data/" + f for f in os.listdir("./Data") if ".cif" in f]
    structures = [IStructure.from_file(cif) for cif in cifs]
    structure = IStructure.from_file("./Data/from_cgcnn/9009743.cif")
    encoded_structure = structure_encoder(structure, radius, max_neighbor_num)
    print(encoded_structure.shape)