Skip to content

Commit

Permalink
Merge pull request #424 from adengz/master
Browse files Browse the repository at this point in the history
Classify sulfur compounds
  • Loading branch information
shyuep committed Jun 26, 2016
2 parents e0aba38 + 6f86181 commit d77d913
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 1 deletion.
46 changes: 46 additions & 0 deletions pymatgen/analysis/structure_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from pymatgen import PeriodicSite
from pymatgen import Element, Specie, Composition
from pymatgen.util.num_utils import abs_cap
from pymatgen.symmetry.analyzer import SpacegroupAnalyzer


class VoronoiCoordFinder(object):
Expand Down Expand Up @@ -610,6 +611,51 @@ def oxide_type(structure, relative_cutoff=1.1, return_nbonds=False):
return ox_obj.oxide_type


def sulfide_type(structure):
"""
Determines if a structure is a sulfide/polysulfide
Args:
structure (Structure): Input structure.
Returns:
(str) sulfide/polysulfide/None.
"""

structure.remove_oxidation_states()
s = Element("S")
comp = structure.composition
if comp.is_element or s not in comp:
return "None"

finder = SpacegroupAnalyzer(structure, symprec=0.1)
symm_structure = finder.get_symmetrized_structure()
distinct_sites = [sites[0] for sites in symm_structure.equivalent_sites]
s_sites = [site for site in distinct_sites if site.specie == s]

def process_site(site):
neighbors = structure.get_neighbors(site, 4)
neighbors = sorted(neighbors, key=lambda n: n[1])
nn, dist = neighbors[0]
coord_elements = [site.specie for site, d in neighbors
if d < dist + 0.4][:4]
avg_electroneg = np.mean([e.X for e in coord_elements])
if avg_electroneg > s.X:
return "sulfATe"
elif avg_electroneg == s.X and s in coord_elements:
return "polysulfide"
else:
return "sulfide"

types = set([process_site(site) for site in s_sites])
if "sulfATe" in types:
return "None"
elif "polysulfide" in types:
return "polysulfide"
else:
return "sulfide"


def gramschmidt(vin, uin):
"""
Returns that part of the first input vector
Expand Down
47 changes: 46 additions & 1 deletion pymatgen/analysis/tests/test_structure_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

from pymatgen.analysis.structure_analyzer import VoronoiCoordFinder, \
solid_angle, contains_peroxide, RelaxationAnalyzer, VoronoiConnectivity, \
oxide_type, OrderParameters, average_coordination_number, VoronoiAnalyzer
oxide_type, sulfide_type, OrderParameters, average_coordination_number, \
VoronoiAnalyzer
from pymatgen.io.vasp.inputs import Poscar
from pymatgen.io.vasp.outputs import Xdatcar
from pymatgen import Element, Structure, Lattice
Expand Down Expand Up @@ -218,6 +219,50 @@ def test_oxide_type(self):
struct = Structure(latt, elts, coords)
self.assertEqual(oxide_type(struct, 1.1), "None")

def test_sulfide_type(self):
# NaS2 -> polysulfide
latt = Lattice.tetragonal(9.59650, 11.78850)
species = ["Na"] * 2 + ["S"] * 2
coords = [[0.00000, 0.00000, 0.17000],
[0.27600, 0.25000, 0.12500],
[0.03400, 0.25000, 0.29600],
[0.14700, 0.11600, 0.40000]]
struct = Structure.from_spacegroup(122, latt, species, coords)
self.assertEqual(sulfide_type(struct), "polysulfide")

# NaCl type NaS -> sulfide
latt = Lattice.cubic(5.75)
species = ["Na", "S"]
coords = [[0.00000, 0.00000, 0.00000],
[0.50000, 0.50000, 0.50000]]
struct = Structure.from_spacegroup(225, latt, species, coords)
self.assertEqual(sulfide_type(struct), "sulfide")

# Na2S2O3 -> None (sulfate)
latt = Lattice.monoclinic(6.40100, 8.10000, 8.47400, 96.8800)
species = ["Na"] * 2 + ["S"] * 2 + ["O"] * 3
coords = [[0.29706, 0.62396, 0.08575],
[0.37673, 0.30411, 0.45416],
[0.52324, 0.10651, 0.21126],
[0.29660, -0.04671, 0.26607],
[0.17577, 0.03720, 0.38049],
[0.38604, -0.20144, 0.33624],
[0.16248, -0.08546, 0.11608]]
struct = Structure.from_spacegroup(14, latt, species, coords)
self.assertEqual(sulfide_type(struct), "None")

# Na3PS3O -> sulfide
latt = Lattice.orthorhombic(9.51050, 11.54630, 5.93230)
species = ["Na"] * 2 + ["S"] * 2 + ["P", "O"]
coords = [[0.19920, 0.11580, 0.24950],
[0.00000, 0.36840, 0.29380],
[0.32210, 0.36730, 0.22530],
[0.50000, 0.11910, 0.27210],
[0.50000, 0.29400, 0.35500],
[0.50000, 0.30300, 0.61140]]
struct = Structure.from_spacegroup(36, latt, species, coords)
self.assertEqual(sulfide_type(struct), "sulfide")


class OrderParametersTest(PymatgenTest):
def setUp(self):
Expand Down

0 comments on commit d77d913

Please sign in to comment.