Skip to content

Commit 17c1411

Browse files
Fixed bug where extra lines in input files would mistakingly be counted as extra atoms for the purpose of checking the number of atoms in the file
1 parent 3300080 commit 17c1411

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
9
2+
3+
C -1.31970 -0.64380 0.00000
4+
H -0.96310 -1.65260 0.00000
5+
H -0.96310 -0.13940 -0.87370
6+
H -2.38970 -0.64380 0.00000
7+
C -0.80640 0.08220 1.25740
8+
H -1.16150 1.09160 1.25640
9+
H -1.16470 -0.42110 2.13110
10+
O 0.62360 0.07990 1.25870
11+
H 0.94410 0.53240 2.04240
12+

ccinput/tests/test_cli.py

+14
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,20 @@ def test_synonym_basis_set(self):
762762

763763
objs, outputs = get_input_from_args(args)
764764

765+
def test_file_extra_line(self):
766+
args = {
767+
"software": "gaussian",
768+
"type": "sp",
769+
"method": "HF",
770+
"basis_set": "Def2SVP",
771+
"file": self.struct("ethanol_extra_line"),
772+
"nproc": 1,
773+
"mem": "1G",
774+
"name": "ethanol",
775+
}
776+
line = f"gaussian sp HF -bs Def2SVP -f {self.struct('ethanol')} -n 1 --mem 1G"
777+
self.assertTrue(self.args_cmd_equivalent(args, line))
778+
765779

766780
class CliPresetTests(InputTests):
767781
def test_create_preset(self):

ccinput/tests/test_structures.py

+15
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,21 @@ def test_multiple_atoms_invalid_header2(self):
8282
with self.assertRaises(InvalidXYZ):
8383
standardize_xyz(xyz)
8484

85+
def test_multiple_atoms_extra_lines(self):
86+
xyz = """3
87+
header
88+
Cl 0.0 0.0 0.0
89+
Cl 0.0 0.0 0.0
90+
Cl 0.0 0.0 0.0
91+
92+
93+
94+
"""
95+
self.assertEqual(
96+
standardize_xyz(xyz),
97+
"Cl 0.00000000 0.00000000 0.00000000\nCl 0.00000000 0.00000000 0.00000000\nCl 0.00000000 0.00000000 0.00000000\n",
98+
)
99+
85100
def test_invalid_element(self):
86101
xyz = "1\n\nBl 0.0 0.0 0.0\n"
87102
with self.assertRaises(InvalidXYZ):

ccinput/utilities.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,14 @@ def parse_xyz_from_file(path):
159159
raise InvalidParameter(f"Input file not found: {path}")
160160

161161
with open(path) as f:
162-
lines = f.readlines()
162+
_lines = f.readlines()
163+
164+
lines = _lines[2:]
165+
166+
if len(_lines) < 3:
167+
raise InvalidXYZ("Invalid XYZ: No atoms specified")
168+
169+
lines = [i.strip() for i in _lines[2:] if i.strip() != ""]
163170

164171
return standardize_xyz(lines)
165172

0 commit comments

Comments
 (0)