Skip to content

Commit

Permalink
Fixed bug where extra lines in input files would mistakingly be count…
Browse files Browse the repository at this point in the history
…ed as extra atoms for the purpose of checking the number of atoms in the file
  • Loading branch information
RaphaelRobidas committed Aug 26, 2024
1 parent 3300080 commit 17c1411
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
12 changes: 12 additions & 0 deletions ccinput/tests/structures/ethanol_extra_line.xyz
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
9

C -1.31970 -0.64380 0.00000
H -0.96310 -1.65260 0.00000
H -0.96310 -0.13940 -0.87370
H -2.38970 -0.64380 0.00000
C -0.80640 0.08220 1.25740
H -1.16150 1.09160 1.25640
H -1.16470 -0.42110 2.13110
O 0.62360 0.07990 1.25870
H 0.94410 0.53240 2.04240

14 changes: 14 additions & 0 deletions ccinput/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,20 @@ def test_synonym_basis_set(self):

objs, outputs = get_input_from_args(args)

def test_file_extra_line(self):
args = {
"software": "gaussian",
"type": "sp",
"method": "HF",
"basis_set": "Def2SVP",
"file": self.struct("ethanol_extra_line"),
"nproc": 1,
"mem": "1G",
"name": "ethanol",
}
line = f"gaussian sp HF -bs Def2SVP -f {self.struct('ethanol')} -n 1 --mem 1G"
self.assertTrue(self.args_cmd_equivalent(args, line))


class CliPresetTests(InputTests):
def test_create_preset(self):
Expand Down
15 changes: 15 additions & 0 deletions ccinput/tests/test_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@ def test_multiple_atoms_invalid_header2(self):
with self.assertRaises(InvalidXYZ):
standardize_xyz(xyz)

def test_multiple_atoms_extra_lines(self):
xyz = """3
header
Cl 0.0 0.0 0.0
Cl 0.0 0.0 0.0
Cl 0.0 0.0 0.0
"""
self.assertEqual(
standardize_xyz(xyz),
"Cl 0.00000000 0.00000000 0.00000000\nCl 0.00000000 0.00000000 0.00000000\nCl 0.00000000 0.00000000 0.00000000\n",
)

def test_invalid_element(self):
xyz = "1\n\nBl 0.0 0.0 0.0\n"
with self.assertRaises(InvalidXYZ):
Expand Down
9 changes: 8 additions & 1 deletion ccinput/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,14 @@ def parse_xyz_from_file(path):
raise InvalidParameter(f"Input file not found: {path}")

with open(path) as f:
lines = f.readlines()
_lines = f.readlines()

lines = _lines[2:]

if len(_lines) < 3:
raise InvalidXYZ("Invalid XYZ: No atoms specified")

lines = [i.strip() for i in _lines[2:] if i.strip() != ""]

return standardize_xyz(lines)

Expand Down

0 comments on commit 17c1411

Please sign in to comment.