From 20e1e357d4f9f0b4121c6de7f7902617a1d28073 Mon Sep 17 00:00:00 2001 From: Alvin Noe Ladines Date: Tue, 3 Sep 2024 14:03:44 +0200 Subject: [PATCH] Fix file parser handling --- atomisticparsers/dftbplus/parser.py | 3 +++ atomisticparsers/gromacs/parser.py | 3 ++- atomisticparsers/h5md/parser.py | 3 ++- atomisticparsers/lammps/parser.py | 8 ++++---- atomisticparsers/namd/parser.py | 2 ++ atomisticparsers/tinker/parser.py | 2 ++ 6 files changed, 15 insertions(+), 6 deletions(-) diff --git a/atomisticparsers/dftbplus/parser.py b/atomisticparsers/dftbplus/parser.py index 5566267..6f02484 100644 --- a/atomisticparsers/dftbplus/parser.py +++ b/atomisticparsers/dftbplus/parser.py @@ -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 @@ -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', '') ) diff --git a/atomisticparsers/gromacs/parser.py b/atomisticparsers/gromacs/parser.py index 9a86404..6fa84a7 100644 --- a/atomisticparsers/gromacs/parser.py +++ b/atomisticparsers/gromacs/parser.py @@ -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 @@ -1578,3 +1577,5 @@ def write_to_archive(self): self.parse_workflow() self.traj_parser.clean() + self.traj_parser.close() + self.energy_parser.close() diff --git a/atomisticparsers/h5md/parser.py b/atomisticparsers/h5md/parser.py index 5aff159..860e5de 100644 --- a/atomisticparsers/h5md/parser.py +++ b/atomisticparsers/h5md/parser.py @@ -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 @@ -898,3 +897,5 @@ def write_to_archive(self) -> None: self.parse_calculation() self.parse_workflow() + + self._data_parser.close() diff --git a/atomisticparsers/lammps/parser.py b/atomisticparsers/lammps/parser.py index 555a763..a200800 100644 --- a/atomisticparsers/lammps/parser.py +++ b/atomisticparsers/lammps/parser.py @@ -18,7 +18,6 @@ # import numpy as np import os -import logging from ase import data as asedata import re @@ -33,7 +32,6 @@ Method, Model, AtomParameters, - Interaction, ) from runschema.system import AtomsGroup from simulationworkflowschema import ( @@ -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 @@ -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() diff --git a/atomisticparsers/namd/parser.py b/atomisticparsers/namd/parser.py index e00f123..955264f 100644 --- a/atomisticparsers/namd/parser.py +++ b/atomisticparsers/namd/parser.py @@ -308,3 +308,5 @@ def get_system_data(index): # workflow self.archive.workflow2 = MolecularDynamics() + + self.traj_parser.close() diff --git a/atomisticparsers/tinker/parser.py b/atomisticparsers/tinker/parser.py index 5fbc71e..6e6baf1 100644 --- a/atomisticparsers/tinker/parser.py +++ b/atomisticparsers/tinker/parser.py @@ -681,3 +681,5 @@ def get_reference_filename(program): self.parse_method() self.parse_workflow(program, run) + + self.traj_parser.close()