Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions PQAnalysis/io/info_file_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,26 +117,30 @@

entry_counter = 0

for line in lines[3:-2]:
line = line.split()
for raw_line in lines[3:]:
if not raw_line.strip():
continue

Check warning on line 122 in PQAnalysis/io/info_file_reader.py

View check run for this annotation

Codecov / codecov/patch

PQAnalysis/io/info_file_reader.py#L122

Added line #L122 was not covered by tests

if len(line) == 8:
if raw_line.lstrip().startswith("-"):
break

info[line[1]] = entry_counter
units[line[1]] = line[3]
entry_counter += 1

info[line[4]] = entry_counter
units[line[4]] = line[6]
entry_counter += 1

else:
line = raw_line.split()

if len(line) not in (5, 8):
self.logger.error(
f"Info file {self.filename} is not in PQ format.",
exception=MDEngineFormatError
)

info[line[1]] = entry_counter
units[line[1]] = line[3]
entry_counter += 1

if len(line) == 8:
info[line[4]] = entry_counter
units[line[4]] = line[6]
entry_counter += 1

return info, units

def _read_qmcfc(self) -> Tuple[Dict, None]:
Expand Down
1 change: 1 addition & 0 deletions tests/data/readEnergyFile/qmmm.en
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 330.958920766485 1687.087653155208 -38105.791953033971 -20573.206966944799 25.000000000000 3946.119527788006 0.000000000000 -26084.300634669558 4605.596120792379 0 1.75899e-14 0.71956
11 changes: 11 additions & 0 deletions tests/data/readEnergyFile/qmmm.info
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-----------------------------------------------------------------------------------------
| PQ info file |
-----------------------------------------------------------------------------------------
| SIMULATION-TIME 0.00200 ps TEMPERATURE 330.95892 K |
| PRESSURE 1687.08765 bar E(TOT) -38105.79195 kcal/mol |
| E(QM) -20573.20697 kcal/mol N(QM-ATOMS) 25.00000 - |
| E(KIN) 3946.11953 kcal/mol E(INTRA) 0.00000 kcal/mol |
| E(COUL) -26084.30063 kcal/mol E(NON-COUL) 4605.59612 kcal/mol |
| N(SM-MOL) 0 - |
| MOMENTUM 1.8e-14 amuA/fs LOOPTIME 0.71956 s |
-----------------------------------------------------------------------------------------
10 changes: 10 additions & 0 deletions tests/io/test_energyFileReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,16 @@ def test_read(self, test_with_data_dir):
assert energy.info_given == True
assert energy.units_given == True

reader = EnergyFileReader("qmmm.en")
energy = reader.read()
assert energy.data.shape == (13, 1)
assert len(energy.info) == 13
assert energy.info["N(SM-MOL)"] == 10
assert energy.units["N(SM-MOL)"] == "-"
assert energy.data[energy.info["N(SM-MOL)"], 0] == 0
assert energy.info["MOMENTUM"] == 11
assert energy.info["LOOPTIME"] == 12

reader = EnergyFileReader("md-01_noinfo.en")
energy = reader.read()
assert np.allclose(energy.data, data_ref)
Expand Down
15 changes: 15 additions & 0 deletions tests/io/test_infoFileReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,18 @@ def test_read(test_with_data_dir):
assert str(
exception.value
) == "Info file md-01.info is not in qmcfc format."


@pytest.mark.parametrize("example_dir", ["readEnergyFile"], indirect=False)
def test_read_pq_info_with_single_entry_row(test_with_data_dir):
reader = InfoFileReader("qmmm.info")

info, units = reader.read()

assert len(info) == 13
assert info["N(SM-MOL)"] == 10
assert units["N(SM-MOL)"] == "-"
assert info["MOMENTUM"] == 11
assert units["MOMENTUM"] == "amuA/fs"
assert info["LOOPTIME"] == 12
assert units["LOOPTIME"] == "s"
Loading