Skip to content

Commit

Permalink
Fix file parser handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ladinesa committed Sep 11, 2024
1 parent eebca28 commit 20e1e35
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 6 deletions.
3 changes: 3 additions & 0 deletions atomisticparsers/dftbplus/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ def parse(self, key=None):
self._results = dict()

geometry = self.mainfile_obj.read()
self.mainfile_obj.close()
if geometry is None:
return

Expand Down Expand Up @@ -281,6 +282,8 @@ def parse(self, key=None):
line = self.hsd.readline()

self.gen_parser.mainfile = self.mainfile
# TODO why is this necessary when you assign mainfile?
# private variables should not be set
self.gen_parser._mainfile_obj = io.StringIO(
self._results.get('data', {}).get('Geometry', {}).get('_block', '')
)
Expand Down
3 changes: 2 additions & 1 deletion atomisticparsers/gromacs/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
logging.warning('Required module MDAnalysis not found.')
MDAnalysis = False
from ase.symbols import symbols2numbers
from nomad.datamodel import EntryArchive
from nomad.units import ureg
from nomad.parsing.file_parser import TextParser, Quantity, FileParser
from runschema.run import Run, Program, TimeRun
Expand Down Expand Up @@ -1578,3 +1577,5 @@ def write_to_archive(self):
self.parse_workflow()

self.traj_parser.clean()
self.traj_parser.close()
self.energy_parser.close()
3 changes: 2 additions & 1 deletion atomisticparsers/h5md/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from typing import List, Dict, Union, Any
from h5py import Group

from nomad.datamodel import EntryArchive
from nomad.metainfo.util import MEnum
from nomad.parsing.file_parser import FileParser
from runschema.run import Run, Program, MSection
Expand Down Expand Up @@ -898,3 +897,5 @@ def write_to_archive(self) -> None:
self.parse_calculation()

self.parse_workflow()

self._data_parser.close()
8 changes: 4 additions & 4 deletions atomisticparsers/lammps/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#
import numpy as np
import os
import logging
from ase import data as asedata
import re

Expand All @@ -33,7 +32,6 @@
Method,
Model,
AtomParameters,
Interaction,
)
from runschema.system import AtomsGroup
from simulationworkflowschema import (
Expand Down Expand Up @@ -1556,8 +1554,6 @@ def parse_method(self):
# if quantity_def and quantity_def.shape:
# # TODO reshape properly
# interaction[key] = [val]
# print("---------", self._mdanalysistraj_parser.mainfile)
# print(interactions)
self.parse_interactions(interactions, sec_model)

# Force Calculation Parameters
Expand Down Expand Up @@ -1751,3 +1747,7 @@ def write_to_archive(self):
self.parse_thermodynamic_data()

self.parse_workflow()

self._mdanalysistraj_parser.close()
for parser in parsers:
parser.close()
2 changes: 2 additions & 0 deletions atomisticparsers/namd/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,3 +308,5 @@ def get_system_data(index):

# workflow
self.archive.workflow2 = MolecularDynamics()

self.traj_parser.close()
2 changes: 2 additions & 0 deletions atomisticparsers/tinker/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,3 +681,5 @@ def get_reference_filename(program):
self.parse_method()

self.parse_workflow(program, run)

self.traj_parser.close()

0 comments on commit 20e1e35

Please sign in to comment.