Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
timurbazhirov committed Mar 22, 2024
1 parent 67e6dbe commit 17deed0
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 21 deletions.
14 changes: 7 additions & 7 deletions jarvis/core/atoms.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""This module provides classes to specify atomic structure."""

import numpy as np
from jarvis.core.composition import Composition
from jarvis.core.specie import Specie, atomic_numbers_to_symbols
Expand Down Expand Up @@ -1452,7 +1453,6 @@ def clone(self):
)



class VacuumPadding(object):
"""Adds vaccum padding to make 2D structure or making molecules."""

Expand Down Expand Up @@ -1881,18 +1881,18 @@ def to_optimade(
info_at["cartesian_site_positions"] = atoms.cart_coords[order].tolist()
info_at["nperiodic_dimensions"] = 3
# info_at["species"] = atoms.elements
info_at[
"species"
] = self.get_optimade_species() # dict(atoms.composition.to_dict())
info_at["species"] = (
self.get_optimade_species()
) # dict(atoms.composition.to_dict())
info_at["elements_ratios"] = list(
atoms.composition.atomic_fraction.values()
)
info_at["structure_features"] = []
info_at["last_modified"] = str(now)
# info_at["more_data_available"] = True
info_at[
"chemical_formula_descriptive"
] = atoms.composition.reduced_formula
info_at["chemical_formula_descriptive"] = (
atoms.composition.reduced_formula
)
info_at["dimension_types"] = [1, 1, 1]
info["attributes"] = info_at
return info
Expand Down
65 changes: 51 additions & 14 deletions jarvis/tests/testfiles/core/test_atoms.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,26 @@
"POSCAR",
)

cif_example = os.path.join(os.path.dirname(__file__), "1000052.cif",)
cif_example2 = os.path.join(os.path.dirname(__file__), "Bacomp.cif",)
cif_example3 = os.path.join(os.path.dirname(__file__), "mock.cif",)
cif_example4 = os.path.join(os.path.dirname(__file__), "exp_000034.cif",)
cif_example5 = os.path.join(os.path.dirname(__file__), "1000000.cif",)
cif_example = os.path.join(
os.path.dirname(__file__),
"1000052.cif",
)
cif_example2 = os.path.join(
os.path.dirname(__file__),
"Bacomp.cif",
)
cif_example3 = os.path.join(
os.path.dirname(__file__),
"mock.cif",
)
cif_example4 = os.path.join(
os.path.dirname(__file__),
"exp_000034.cif",
)
cif_example5 = os.path.join(
os.path.dirname(__file__),
"1000000.cif",
)


def test_from_cif():
Expand All @@ -82,7 +97,11 @@ def test_from_cif():

def test_basic_atoms():

Si = Atoms(lattice_mat=FIXTURES["lattice_mat"], coords=FIXTURES["coords"], elements=FIXTURES["elements"])
Si = Atoms(
lattice_mat=FIXTURES["lattice_mat"],
coords=FIXTURES["coords"],
elements=FIXTURES["elements"],
)
dim = get_supercell_dims(Si)
build_xanes_poscar(atoms=Si, filename_with_prefix=True)
assert dim == [3, 3, 3]
Expand Down Expand Up @@ -112,8 +131,8 @@ def test_basic_atoms():
prim = Si.get_primitive_atoms
print(prim.cart_coords)
conv = Si.get_conventional_atoms
spgn=Si.get_spacegroup
comp=compare_atoms(atoms1=prim,atoms2=conv)
spgn = Si.get_spacegroup
comp = compare_atoms(atoms1=prim, atoms2=conv)
assert round(prim.cart_coords[0][0], 2) == round(4.37815150, 2)
# print ('raw_distance_matrix', prim.raw_distance_matrix)
# print ('raw_distance_matrix', Si.raw_distance_matrix)
Expand Down Expand Up @@ -211,14 +230,32 @@ def test_basic_atoms():
cmd = "rm atoms.xyz POSCAR atoms.cif"
os.system(cmd)


def test_clone():
Si = Atoms(lattice_mat=FIXTURES["lattice_mat"], coords=FIXTURES["coords"], elements=FIXTURES["elements"])
Si = Atoms(
lattice_mat=FIXTURES["lattice_mat"],
coords=FIXTURES["coords"],
elements=FIXTURES["elements"],
)
Si2 = Si.clone()
assert (Si2.lattice_mat == Si.lattice_mat and Si2.coords == Si.coords and Si2.elements == Si.elements
and Si2.props == Si.props and Si2.cartesian == Si.cartesian and Si2.show_props == Si.show_props)
assert (
Si2.lattice_mat == Si.lattice_mat
and Si2.coords == Si.coords
and Si2.elements == Si.elements
and Si2.props == Si.props
and Si2.cartesian == Si.cartesian
and Si2.show_props == Si.show_props
)


def test_remove_sites_by_indices():
Si = Atoms(lattice_mat=FIXTURES["lattice_mat"], coords=FIXTURES["coords"], elements=FIXTURES["elements"])
Si = Atoms(
lattice_mat=FIXTURES["lattice_mat"],
coords=FIXTURES["coords"],
elements=FIXTURES["elements"],
)
Si_supercell = Si.make_supercell([2, 2, 2])
Si2_supercell_without_two_atoms = Si_supercell.remove_sites_by_indices(indices=[0, 1])
assert (Si2_supercell_without_two_atoms.num_atoms == 14)
Si2_supercell_without_two_atoms = Si_supercell.remove_sites_by_indices(
indices=[0, 1]
)
assert Si2_supercell_without_two_atoms.num_atoms == 14

0 comments on commit 17deed0

Please sign in to comment.