From 67ec7c94f9c2824fb8e825e5f4745646d242171b Mon Sep 17 00:00:00 2001 From: robinzyb <38876805+robinzyb@users.noreply.github.com> Date: Mon, 1 Jul 2024 23:48:38 +0200 Subject: [PATCH 1/5] bump to 0.7.1 --- .github/workflows/ci.yml | 2 +- pyproject.toml | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bdca81c..7d9ddda 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.8', '3.9', '3.10'] + python-version: ['3.7', '3.8', '3.9', '3.10'] steps: - uses: actions/checkout@v2 diff --git a/pyproject.toml b/pyproject.toml index 7bb23d8..418c7c6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta" [project] name = "Cp2kData" -version = "0.7.0" +version = "0.7.1" description = "A Small Package to Postprocess Cp2k Output" authors = [ {name = "Yongbin Zhuang", email = "robinzhuang@outlook.com"} @@ -15,6 +15,7 @@ authors = [ license = {file = "LICENSE"} readme = "README.md" classifiers = [ + "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", @@ -34,7 +35,7 @@ dependencies = [ "pycp2k", "asciichartpy" ] -requires-python = ">=3.8" +requires-python = ">=3.7" keywords = ["cp2k", "cp2kdata"] [project.urls] From dfc6067f1c1e01ab416b68172279bdaf7157b514 Mon Sep 17 00:00:00 2001 From: robinzyb <38876805+robinzyb@users.noreply.github.com> Date: Mon, 1 Jul 2024 23:50:21 +0200 Subject: [PATCH 2/5] compat version of numpy --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 418c7c6..34c44fd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,7 +22,7 @@ classifiers = [ "License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)" ] dependencies = [ - "numpy>=1.24.3", + "numpy>=1.21.6", "scipy>=1.5.4", "matplotlib>=3.3.2", "ase>=3.20.1", From 7db871af8a4229863c53dff23945d92e55bf4352 Mon Sep 17 00:00:00 2001 From: robinzyb <38876805+robinzyb@users.noreply.github.com> Date: Tue, 2 Jul 2024 15:08:04 +0200 Subject: [PATCH 3/5] disable python 3.7 --- pyproject.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 34c44fd..7816902 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,7 +15,6 @@ authors = [ license = {file = "LICENSE"} readme = "README.md" classifiers = [ - "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", @@ -35,7 +34,7 @@ dependencies = [ "pycp2k", "asciichartpy" ] -requires-python = ">=3.7" +requires-python = ">=3.8" keywords = ["cp2k", "cp2kdata"] [project.urls] From 7bb86803ecebe3d078c05573510eb6aefcf7ba32 Mon Sep 17 00:00:00 2001 From: robinzyb <38876805+robinzyb@users.noreply.github.com> Date: Tue, 2 Jul 2024 15:35:28 +0200 Subject: [PATCH 4/5] modify workflow --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7d9ddda..bdca81c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.7', '3.8', '3.9', '3.10'] + python-version: ['3.8', '3.9', '3.10'] steps: - uses: actions/checkout@v2 From 221ecdcf2882cd521b37a39ed9a2be7b1ec4b211 Mon Sep 17 00:00:00 2001 From: robinzyb <38876805+robinzyb@users.noreply.github.com> Date: Fri, 12 Jul 2024 13:24:24 +0200 Subject: [PATCH 5/5] usa logging in output.py --- cp2kdata/dpdata_plugin.py | 11 +++--- cp2kdata/log.py | 2 +- cp2kdata/output.py | 71 +++++++++++++++++++-------------------- 3 files changed, 42 insertions(+), 42 deletions(-) diff --git a/cp2kdata/dpdata_plugin.py b/cp2kdata/dpdata_plugin.py index b59932b..d09091c 100644 --- a/cp2kdata/dpdata_plugin.py +++ b/cp2kdata/dpdata_plugin.py @@ -1,12 +1,13 @@ -from .log import get_logger + import numpy as np -from dpdata.unit import EnergyConversion, LengthConversion, ForceConversion, PressureConversion +from dpdata.unit import EnergyConversion, LengthConversion, PressureConversion from dpdata.format import Format -from . import Cp2kOutput -from .block_parser.converge import parse_e_f_converge -from .block_parser.md_xyz import parse_pos_xyz_from_wannier +from cp2kdata import Cp2kOutput +from cp2kdata.log import get_logger +from cp2kdata.block_parser.converge import parse_e_f_converge + logger = get_logger(__name__) diff --git a/cp2kdata/log.py b/cp2kdata/log.py index da313fa..bb4f4a6 100644 --- a/cp2kdata/log.py +++ b/cp2kdata/log.py @@ -5,7 +5,7 @@ level = logging._nameToLevel.get(level_name, logging.INFO) # format to include timestamp and module -logging.basicConfig(format='%(asctime)s %(levelname)-8s %(name)-40s: %(message)s', level=level) +logging.basicConfig(format='CP2KDATA| %(levelname)-8s %(name)-40s: %(message)s', level=level) # suppress transitions logging # logging.getLogger('transitions.core').setLevel(logging.WARNING) diff --git a/cp2kdata/output.py b/cp2kdata/output.py index 4441a01..424bd2e 100644 --- a/cp2kdata/output.py +++ b/cp2kdata/output.py @@ -4,10 +4,11 @@ import os import sys from functools import cached_property -from .plots.geo_opt_plot import geo_opt_info_plot -from .block_parser.header_info import GlobalInfo, Cp2kInfo, DFTInfo +from cp2kdata.plots.geo_opt_plot import geo_opt_info_plot +from cp2kdata.log import get_logger from cp2kdata.utils import format_logger +from cp2kdata.block_parser.header_info import GlobalInfo, Cp2kInfo, DFTInfo from cp2kdata.block_parser.dft_plus_u import parse_dft_plus_u_occ from cp2kdata.block_parser.forces import parse_atomic_forces_list from cp2kdata.block_parser.geo_opt import parse_geo_opt_info @@ -23,21 +24,22 @@ from cp2kdata.block_parser.md_xyz import parse_md_ener, parse_pos_xyz, parse_frc_xyz, parse_md_stress, parse_md_cell from cp2kdata.block_parser.vibration import parse_vibration_freq_list +logger = get_logger(__name__) class Cp2kOutput: """Class for parsing cp2k output""" def __init__( self, - output_file: str=None, - run_type: str=None, - path_prefix: str=".", - restart: bool=None, + output_file: str = None, + run_type: str = None, + path_prefix: str = ".", + restart: bool = None, **kwargs - ): + ): # --set some basic information - #self.required_information = kwargs + # self.required_information = kwargs self.path_prefix = path_prefix if output_file is None: @@ -53,7 +55,7 @@ def __init__( filename=self.filename ) except ValueError as err: - print( + logger.error( "---------------------------------------------\n" "Cannot Obtain CP2K RUN_TYPE information.\n" @@ -110,7 +112,8 @@ def __init__( } # call corresponding parser for run types - parse_run_type = run_type_parser_candidates.get(self.global_info.run_type, None) + parse_run_type = run_type_parser_candidates.get( + self.global_info.run_type, None) if parse_run_type: parse_run_type() else: @@ -323,14 +326,6 @@ def to_ase_atoms(self): pass def parse_energy_force(self): - parser_candidates = { - "energy": parse_energies_list, - "forces": parse_atomic_forces_list, - "stress_tensor": parse_stress_tensor_list, - "atomic_kinds": parse_atomic_kinds, - "cells": parse_all_cells - } - # TODO: convert kwargs to flexible attribute! self.geo_opt_info = None self.num_frames = 1 self.init_atomic_coordinates, self.atom_kind_list, self.chemical_symbols = parse_init_atomic_coordinates( @@ -384,7 +379,7 @@ def parse_md(self): pos_xyz_file_list = glob.glob( os.path.join(self.path_prefix, "*pos*.xyz")) if pos_xyz_file_list: - #TODO: Is it possible to have no pos file? + # TODO: Is it possible to have no pos file? self.atomic_frames_list, energies_list_from_pos, self.chemical_symbols = parse_pos_xyz( pos_xyz_file_list[0]) @@ -394,7 +389,8 @@ def parse_md(self): # if no pos file and ener file, parse energies from the output file format_logger(info="Energies", filename=self.filename) self.energies_list = parse_energies_list(self.output_file) - self.energies_list = self.drop_last_info(self.cp2k_info, self.energies_list) + self.energies_list = self.drop_last_info( + self.cp2k_info, self.energies_list) self.atomic_frames_list = None frc_xyz_file_list = glob.glob( @@ -405,26 +401,28 @@ def parse_md(self): format_logger(info="Forces", filename=self.filename) self.atomic_forces_list = parse_atomic_forces_list( self.output_file) - self.atomic_forces_list = self.drop_last_info(self.cp2k_info, self.atomic_forces_list) + self.atomic_forces_list = self.drop_last_info( + self.cp2k_info, self.atomic_forces_list) stress_file_list = glob.glob( os.path.join(self.path_prefix, "*.stress")) if stress_file_list: - print( + logger.warning( f"cp2kdata found a file recording stresses: {stress_file_list[0]}" f"But the parser for {stress_file_list[0]} is not supported yet" - ) - #TODO: the unit of stress is bar in -1.stress file, but not GPa in the output file - #TODO: however, covert bar to GPa is not consistent with the output file! - #TODO: check this latter - #self.stress_tensor_list = parse_md_stress(stress_file_list[0]) + ) + # TODO: the unit of stress is bar in -1.stress file, but not GPa in the output file + # TODO: however, covert bar to GPa is not consistent with the output file! + # TODO: check this latter + # self.stress_tensor_list = parse_md_stress(stress_file_list[0]) self.stress_tensor_list = None else: format_logger(info="Stresses", filename=self.filename) self.stress_tensor_list = parse_stress_tensor_list( self.output_file) - self.stress_tensor_list = self.drop_last_info(self.cp2k_info, self.stress_tensor_list) + self.stress_tensor_list = self.drop_last_info( + self.cp2k_info, self.stress_tensor_list) self.num_frames = len(self.energies_list) @@ -454,18 +452,17 @@ def parse_md(self): "------------------\n" ) - cell_file_list = glob.glob(os.path.join(self.path_prefix, "*.cell")) if (self.md_info.ensemble_type == "NVT") or \ (self.md_info.ensemble_type == "NVE") or \ - (self.md_info.ensemble_type == "REFTRAJ"): # not ture REFTRAJ also contrains different cell? + (self.md_info.ensemble_type == "REFTRAJ"): # not ture REFTRAJ also contrains different cell? if cell_file_list: self.all_cells = parse_md_cell(cell_file_list[0]) elif self.filename: format_logger(info="Cells", filename=self.filename) - print(WARNING_MSG_PARSE_CELL_FROM_OUTPUT) + logger.warning(WARNING_MSG_PARSE_CELL_FROM_OUTPUT) - #self.organize_md_cell() + # self.organize_md_cell() # parse the first cell first_cell = parse_all_cells(self.output_file) assert first_cell.shape == (1, 3, 3) @@ -479,7 +476,7 @@ def parse_md(self): self.all_cells = parse_md_cell(cell_file_list[0]) elif self.filename: format_logger(info="Cells", filename=self.filename) - print(WARNING_MSG_PARSE_CELL_FROM_OUTPUT) + logger.warning(WARNING_MSG_PARSE_CELL_FROM_OUTPUT) self.organize_md_cell() @@ -488,7 +485,7 @@ def parse_md(self): self.all_cells = parse_md_cell(cell_file_list[0]) elif self.filename: format_logger(info="Cells", filename=self.filename) - print(WARNING_MSG_PARSE_CELL_FROM_OUTPUT) + logger.warning(WARNING_MSG_PARSE_CELL_FROM_OUTPUT) self.organize_md_cell() @@ -527,7 +524,8 @@ def get_vib_freq_list(self): def drop_last_info(cp2k_info, array): # drop last info parsed from output if it is terminated by request (touch EXIT) if cp2k_info.terminated_by_request == True: - print("cp2kdata found the cp2k output is terminated by request, drop the last info.") + print( + "cp2kdata found the cp2k output is terminated by request, drop the last info.") array = array[:-1] return array @@ -544,7 +542,8 @@ def get_global_info(run_type=None, filename=None): @staticmethod def check_run_type(run_type): implemented_run_type_parsers = \ - ["ENERGY_FORCE", "ENERGY", "MD", "GEO_OPT", "CELL_OPT", "VIBRATIONAL_ANALYSIS"] + ["ENERGY_FORCE", "ENERGY", "MD", "GEO_OPT", + "CELL_OPT", "VIBRATIONAL_ANALYSIS"] if run_type not in implemented_run_type_parsers: raise ValueError( f"Parser for Run Type {run_type} haven't been implemented yet!"