Skip to content

Commit 1da6f63

Browse files
committed
fixed reading aims input files with no lattice
1 parent 99a0652 commit 1da6f63

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

changes/orphan.1.fix.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
reading fhiaims input geometries for molecules
2+
3+
Previously it failed when the lattice was not
4+
defined in the file. Now it reads but puts
5+
an arbitrary lattice.

src/sisl/_core/geometry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def _init_lattice(self, lattice: Optional[LatticeLike]) -> None:
223223

224224
# First create an initial guess for the supercell
225225
# It HAS to be VERY large to not interact
226-
closest = self.close(0, R=(0.0, 0.4, 5.0))[2]
226+
closest = self.close(0, R=(0.4, 5.0))[1]
227227
if len(closest) < 1:
228228
# We could not find any atoms very close,
229229
# hence we simply return and now it becomes

src/sisl/io/fhiaims/_geometry.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def write_geometry(
8888
self._write(_fmtm.format(moment[ia]))
8989

9090
@sile_fh_open()
91-
def read_lattice(self) -> Lattice:
91+
def read_lattice(self) -> Lattice | None:
9292
"""Reads supercell object from the file"""
9393
self.fh.seek(0)
9494

@@ -98,7 +98,9 @@ def read_lattice(self) -> Lattice:
9898
if line.startswith("lattice_vector"):
9999
cell.append([float(f) for f in line.split()[1:]])
100100

101-
return Lattice(cell)
101+
if cell:
102+
return Lattice(cell)
103+
return None
102104

103105
@sile_fh_open()
104106
@deprecate_argument(

src/sisl/io/fhiaims/tests/test_in.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,23 @@ def test_in_simple(sisl_tmp, sisl_system):
2323
assert sisl_system.g.atoms.equal(g.atoms, R=False)
2424

2525

26+
def test_in_no_lattice(sisl_tmp, sisl_system):
27+
# test when the input geometry does not have any lattice.
28+
# In this case it shouldn't be used.
29+
f = sisl_tmp("gr.in")
30+
g = sisl_system.g
31+
with open(f, "w") as fh:
32+
for atom, xyz in zip(g.atoms, g.xyz):
33+
fh.write(f"atom {xyz[0]} {xyz[1]} {xyz[2]} {atom.symbol}\n")
34+
35+
gr = inSileFHIaims(f).read_geometry()
36+
37+
# Assert they are the same
38+
assert not np.allclose(gr.cell, g.cell)
39+
assert np.allclose(gr.xyz, g.xyz)
40+
assert gr.atoms.equal(g.atoms, R=False)
41+
42+
2643
def test_in_velocity(sisl_tmp, sisl_system):
2744
f = sisl_tmp("gr.in")
2845
g = sisl_system.g.copy()

0 commit comments

Comments
 (0)