How to use the smact.Species function in SMACT

To help you get started, we’ve selected a few SMACT examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github WMD-group / SMACT / examples / LatticeParameters / lattice_parameters_example.py View on Github external
print (" \n=========================================")
    print ("    EEEEE   ####### ##   ## #####  #####")
    print ("   EE         ##     ## ## ##  ## ##")
    print ("  EEEE  ###  ##      ##   #####  #####")
    print (" EE         ##      ##   ##     ##")
    print ("EEEEE      ##      ##   ##     #####")
    print ("=========================================")

    print (" \n ### E type lattices ###\n ")

    for lattice in e_lattices:
        print((' \n===============\n ') + lattice.__name__.upper() + (' Lattice \n===============\n  '))
        shannon_radius = []
        for i, elements in enumerate(crystal_elements):
            print(elements,oxidation[i],coordination[i])
            x = smact.Species(elements,oxidation[i],coordination[i])
            shannon_radius.append(float(x.shannon_radius))
        a,b,c,space,alpha,beta,gamma = lattice(shannon_radius)
        print(crystal_elements[0:],"%.2f"%a,"%.2f"%b,"%.2f"%c,"%.1f"%alpha,"%.1f"%beta,"%.1f"%gamma)
        print ("With a gap in the middle of " + "%.2f"%space+" (diameter)")
github WMD-group / SMACT / smact / oxidation_states.py View on Github external
Args:
            structure (pymatgen.Structure): Compound for which the probability score will be generated.
                Can also be a list of pymatgen or SMACT Species.
            ignore_stoichiometry (bool): Whether to weight probabilities by stoichiometry.
                Defaults to false as decribed in the original paper.

        Returns:
            compound_prob (float): Compound probability
        '''

        # Convert input to list of SMACT Species
        if type(structure) == list:
            if all(isinstance(i, Species) for i in structure):
                pass
            elif all(isinstance(i, pmgSpecies) for i in structure):
                structure = [Species(i.symbol,i.oxi_state) for i in structure]
            else:
                raise TypeError("Input requires a list of SMACT or Pymatgen species.")
        elif type(structure) == Structure:
            species = structure.species
            if not all(isinstance(i, pmgSpecies) for i in species):
                raise TypeError("Structure must have oxidation states.")
            else:
                structure = [Species(i.symbol, i.oxi_state) for i in structure]
        else:
            raise TypeError("Input requires a list of SMACT or Pymatgen Species or a Structure.")

        # Put most electonegative element last in list by sorting by electroneg
        structure.sort(key=lambda x: x.pauling_eneg)

        # Define necessary species pairs
        anion = structure[-1]
github WMD-group / SMACT / smact / oxidation_states.py View on Github external
'''
        calculate overall probability for structure or composition.

        Args:
            structure (pymatgen.Structure): Compound for which the probability score will be generated.
                Can also be a list of pymatgen or SMACT Species.
            ignore_stoichiometry (bool): Whether to weight probabilities by stoichiometry.
                Defaults to false as decribed in the original paper.

        Returns:
            compound_prob (float): Compound probability
        '''

        # Convert input to list of SMACT Species
        if type(structure) == list:
            if all(isinstance(i, Species) for i in structure):
                pass
            elif all(isinstance(i, pmgSpecies) for i in structure):
                structure = [Species(i.symbol,i.oxi_state) for i in structure]
            else:
                raise TypeError("Input requires a list of SMACT or Pymatgen species.")
        elif type(structure) == Structure:
            species = structure.species
            if not all(isinstance(i, pmgSpecies) for i in species):
                raise TypeError("Structure must have oxidation states.")
            else:
                structure = [Species(i.symbol, i.oxi_state) for i in structure]
        else:
            raise TypeError("Input requires a list of SMACT or Pymatgen Species or a Structure.")

        # Put most electonegative element last in list by sorting by electroneg
        structure.sort(key=lambda x: x.pauling_eneg)
github WMD-group / SMACT / smact / structure_prediction / structure.py View on Github external
raise TypeError(f"`species` must be a list of tuples, got list of {type(species[0])}.")

        species_error = (
          "`species` list of tuples must contain either "
          "2-tuples of Species objects and stoichiometries, "
          "or 3-tuples of elements, oxidations and stoichiometries."
        )
        if len(species[0]) not in {2, 3}:
            raise ValueError(species_error)

        if isinstance(species[0][0], str):  # String variation of instantiation
            species.sort(key=itemgetter(1), reverse=True)
            species.sort(key=itemgetter(0))
            sanit_species = species

        elif isinstance(species[0][0], smact.Species):  # Species class variation of instantiation
            species.sort(key=lambda x: (x[0].symbol, -x[0].oxidation))
            sanit_species = [(x[0].symbol, x[0].oxidation, x[1]) for x in species]

        else:
            raise TypeError(species_error)

        return sanit_species
github WMD-group / SMACT / examples / LatticeParameters / lattice_parameters_example.py View on Github external
print (" \n=========================================")
    print ("    BBBB     ####### ##   ## #####  #####")
    print ("   BB BB       ##     ## ## ##  ## ##")
    print ("  BBBB   ###  ##      ##   #####  #####")
    print (" BB BB       ##      ##   ##     ##")
    print ("BBBB        ##      ##   ##     #####")
    print ("=========================================")

    print (" \n ### B type lattices ###\n ")

    for lattice in b_lattices:
        print((' \n===============\n ') + lattice.__name__.upper() + (' Lattice \n===============\n  '))
        shannon_radius = []
        for i, elements in enumerate(crystal_elements):
            print(elements,oxidation[i],coordination[i])
            x = smact.Species(elements,oxidation[i],coordination[i])
            shannon_radius.append(float(x.shannon_radius))
        a,b,c,alpha,beta,gamma = lattice(shannon_radius)
        if lattice.__name__ == 'wurtzite':
            inner_space = a * (6**0.5) - (4*shannon_radius[0])
            print ("With a gap in the middle of " + "%.2f"%inner_space+" (diameter)")
        print(crystal_elements[0:2],"%.2f"%a,"%.2f"%b,"%.2f"%c,"%.1f"%alpha,"%.1f"%beta,"%.1f"%gamma)

    # E Types
    #-------------------------------------------------------------------------------------#
    print (" \n=========================================")
    print ("    EEEEE   ####### ##   ## #####  #####")
    print ("   EE         ##     ## ## ##  ## ##")
    print ("  EEEE  ###  ##      ##   #####  #####")
    print (" EE         ##      ##   ##     ##")
    print ("EEEEE      ##      ##   ##     #####")
    print ("=========================================")