From 0aff4d0feb789fcf5df6dfd7790d783bddebed8d Mon Sep 17 00:00:00 2001 From: pxlxingliang Date: Mon, 12 Aug 2024 17:29:15 +0800 Subject: [PATCH 01/11] add the prepare for spin case --- fpop/abacus.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/fpop/abacus.py b/fpop/abacus.py index 81e87e2..6598cbd 100644 --- a/fpop/abacus.py +++ b/fpop/abacus.py @@ -10,7 +10,7 @@ Set, Dict, Optional, - Union, + Union ) import numpy as np from dflow.python import ( @@ -348,6 +348,12 @@ def __init__( self._deepks_descriptor = None if deepks_descriptor == None else (os.path.split(deepks_descriptor)[1], Path(deepks_descriptor).read_text()) self._deepks_model = None if deepks_model == None else (os.path.split(deepks_model)[1], Path(deepks_model).read_bytes()) + def spin_constrain(self): + sc = self._input.get("sc_mag_switch","") + if sc.lower() in ["","f","false", "0", ".false."]: + return False + return True + def _read_dict_file(self,input_dict,out_dict=None): # input_dict is a dict whose value is a file. # The filename and context will make up a tuple, which is @@ -542,7 +548,17 @@ def prep_task( pp, orb = abacus_inputs.write_pporb(element_list) dpks = abacus_inputs.write_deepks() mass = abacus_inputs.get_mass(element_list) - conf_frame.to('abacus/stru', 'STRU', pp_file=pp,numerical_orbital=orb,numerical_descriptor=dpks,mass=mass) + + # if spin constrain, need to write the mag and sc to STRU + mag = None + sc = None + if abacus_inputs.spin_constrain(): + mag = conf_frame.data.get("spin",None) + if mag is not None: + mag = mag[0] + sc = [[1,1,1]] * len(mag) # constrain all atoms in x,y,z direction + + conf_frame.to('abacus/stru', 'STRU', pp_file=pp,numerical_orbital=orb,numerical_descriptor=dpks,mass=mass,mag=mag,sc=sc) abacus_inputs.write_input("INPUT") abacus_inputs.write_kpt("KPT") From 13876025723c242cfa3795a85487b8e09e6c7cca Mon Sep 17 00:00:00 2001 From: root Date: Tue, 10 Sep 2024 15:25:33 +0800 Subject: [PATCH 02/11] fix and add UT --- fpop/abacus.py | 2 +- tests/test_prep_abacus.py | 60 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/fpop/abacus.py b/fpop/abacus.py index 6598cbd..1b0107b 100644 --- a/fpop/abacus.py +++ b/fpop/abacus.py @@ -553,7 +553,7 @@ def prep_task( mag = None sc = None if abacus_inputs.spin_constrain(): - mag = conf_frame.data.get("spin",None) + mag = conf_frame.data.get("spins",None) if mag is not None: mag = mag[0] sc = [[1,1,1]] * len(mag) # constrain all atoms in x,y,z direction diff --git a/tests/test_prep_abacus.py b/tests/test_prep_abacus.py index 7c69c86..5c3c85b 100644 --- a/tests/test_prep_abacus.py +++ b/tests/test_prep_abacus.py @@ -29,7 +29,7 @@ import time, shutil, dpdata from pathlib import Path -from context import ( +from .context import ( fpop, default_image, upload_python_packages, @@ -38,10 +38,11 @@ ) from fpop.abacus import PrepAbacus,AbacusInputs from typing import List -from constants import POSCAR_1_content,POSCAR_2_content,dump_conf_from_poscar +from .constants import POSCAR_1_content,POSCAR_2_content,dump_conf_from_poscar upload_packages.append("../fpop") upload_packages.append("./context.py") + class TestPrepAbacus(unittest.TestCase): ''' deepmd/npy format named ["data.000","data.001"]. @@ -200,4 +201,59 @@ def testWithoutOptionalParam(self): self.assertEqual(tdirs, step.outputs.parameters['task_names'].value) +class TestPrepAbacusSpin(unittest.TestCase): + ''' + deepmd/npy format named ["data.000","data.001"]. + no optional_input or optional_artifact. + ''' + def setUp(self): + self.source_path = Path('abacustest') + self.word_path = Path('task.000') + self.source_path.mkdir(parents=True, exist_ok=True) + self.word_path.mkdir(parents=True, exist_ok=True) + + poscar_path = self.source_path / "POSCAR_tmp" + poscar_path.write_text(POSCAR_1_content) + self.confs = dpdata.System(poscar_path, fmt="vasp/poscar") + self.confs.data["spins"] = [[[1,2,3]]] + + (self.source_path/"INPUT").write_text('INPUT_PARAMETERS\ncalculation scf\nbasis_type lcao\nsc_mag_switch 1\n') + (self.source_path/"KPT").write_text('here kpt') + (self.source_path/"Na.upf").write_text('here upf') + (self.source_path/"Na.orb").write_text('here orb') + (self.source_path/'optional_test').write_text('here test') + + self.abacus_inputs = AbacusInputs( + input_file=self.source_path/"INPUT", + kpt_file=self.source_path/"KPT", + pp_files={"Na":self.source_path/"Na.upf"}, + orb_files={"Na":self.source_path/"Na.orb"} + ) + + def tearDown(self): + if os.path.isdir(self.source_path): + shutil.rmtree(self.source_path) + if os.path.isdir(self.word_path): + shutil.rmtree(self.word_path) + + def test_prepare_abacus_spin(self): + pabacus = PrepAbacus() + os.chdir(self.word_path) + + pabacus.prep_task(self.confs, self.abacus_inputs) + + self.assertTrue(os.path.isfile('INPUT')) + self.assertTrue(os.path.isfile('KPT')) + self.assertTrue(os.path.isfile('STRU')) + self.assertTrue(os.path.isfile('Na.upf')) + self.assertTrue(os.path.isfile('Na.orb')) + self.assertEqual(Path('INPUT').read_text().split()[0],"INPUT_PARAMETERS") + self.assertEqual(Path('KPT').read_text(),'here kpt') + self.assertEqual(Path('Na.upf').read_text(),'here upf') + self.assertEqual(Path('Na.orb').read_text(),'here orb') + + with open("STRU") as f : c = f.read() + self.assertTrue("0.000000000000 0.000000000000 0.000000000000 1 1 1 mag 1.000000000000 2.000000000000 3.000000000000 sc 1 1 1" in c) + + os.chdir("../") From fcb9ad62871199a2d658f989048eda07ba0e81ec Mon Sep 17 00:00:00 2001 From: root Date: Thu, 12 Sep 2024 09:21:23 +0800 Subject: [PATCH 03/11] fix --- tests/test_prep_abacus.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_prep_abacus.py b/tests/test_prep_abacus.py index 5c3c85b..31ecf26 100644 --- a/tests/test_prep_abacus.py +++ b/tests/test_prep_abacus.py @@ -29,7 +29,7 @@ import time, shutil, dpdata from pathlib import Path -from .context import ( +from context import ( fpop, default_image, upload_python_packages, @@ -38,7 +38,7 @@ ) from fpop.abacus import PrepAbacus,AbacusInputs from typing import List -from .constants import POSCAR_1_content,POSCAR_2_content,dump_conf_from_poscar +from constants import POSCAR_1_content,POSCAR_2_content,dump_conf_from_poscar upload_packages.append("../fpop") upload_packages.append("./context.py") From 33ca6145da15c222734ba5adf5ed246ddcf990ad Mon Sep 17 00:00:00 2001 From: root Date: Tue, 8 Oct 2024 16:34:38 +0800 Subject: [PATCH 04/11] add the option constrain_elements --- fpop/abacus.py | 34 ++++++++++++++---------- tests/test_prep_abacus.py | 54 +++++++++++++++++++++++++++------------ 2 files changed, 58 insertions(+), 30 deletions(-) diff --git a/fpop/abacus.py b/fpop/abacus.py index 1b0107b..8c83b71 100644 --- a/fpop/abacus.py +++ b/fpop/abacus.py @@ -314,7 +314,8 @@ def __init__( kpt_file: Optional[Union[str,Path]] = None, orb_files: Optional[Dict[str, Union[str,Path]]] = None, deepks_descriptor: Optional[Union[str,Path]] = None, - deepks_model: Optional[Union[str,Path]] = None + deepks_model: Optional[Union[str,Path]] = None, + constrain_elements: Optional[List[str]] = None, ): """The input information of an ABACUS job except for STRU. @@ -337,6 +338,9 @@ def __init__( The deepks descriptor file, by default None. deepks_model : str, optional The deepks model file, by default None. + constrain_elements : List[str], optional + The elements that need to constrain the magnetic moment, by default None. + For the constrained elements, the flag "sc 1 1 1" will be added in STRU. """ self.input_file = input_file self._input = AbacusInputs.read_inputf(self.input_file) @@ -347,12 +351,7 @@ def __init__( self._orb_files = {} if orb_files == None else self._read_dict_file(orb_files) self._deepks_descriptor = None if deepks_descriptor == None else (os.path.split(deepks_descriptor)[1], Path(deepks_descriptor).read_text()) self._deepks_model = None if deepks_model == None else (os.path.split(deepks_model)[1], Path(deepks_model).read_bytes()) - - def spin_constrain(self): - sc = self._input.get("sc_mag_switch","") - if sc.lower() in ["","f","false", "0", ".false."]: - return False - return True + self._constrin_elements = constrain_elements def _read_dict_file(self,input_dict,out_dict=None): # input_dict is a dict whose value is a file. @@ -400,6 +399,9 @@ def get_deepks_descriptor(self): def get_deepks_model(self): return self._deepks_model + + def get_constrain_elements(self): + return self._constrin_elements @staticmethod def read_inputf(inputf: Union[str,Path]) -> dict: @@ -549,14 +551,18 @@ def prep_task( dpks = abacus_inputs.write_deepks() mass = abacus_inputs.get_mass(element_list) - # if spin constrain, need to write the mag and sc to STRU - mag = None + # if conf_frame has the spins, then we will use it as the initial mag and write it to STRU + mag = conf_frame.data.get("spins",None) + if mag is not None: + mag = mag[0] # spins is the mag of several frames, here we only use the first frame + + # if the constrain_elements is set, we will set the related flag in STRU sc = None - if abacus_inputs.spin_constrain(): - mag = conf_frame.data.get("spins",None) - if mag is not None: - mag = mag[0] - sc = [[1,1,1]] * len(mag) # constrain all atoms in x,y,z direction + c_eles = abacus_inputs.get_constrain_elements() + if c_eles: + atom_names = conf_frame.data["atom_names"] + atom_types = [atom_names[i] for i in conf_frame.data["atom_types"]] + sc = [None if i not in c_eles else [1,1,1] for i in atom_types] conf_frame.to('abacus/stru', 'STRU', pp_file=pp,numerical_orbital=orb,numerical_descriptor=dpks,mass=mass,mag=mag,sc=sc) diff --git a/tests/test_prep_abacus.py b/tests/test_prep_abacus.py index 31ecf26..708b705 100644 --- a/tests/test_prep_abacus.py +++ b/tests/test_prep_abacus.py @@ -38,7 +38,7 @@ ) from fpop.abacus import PrepAbacus,AbacusInputs from typing import List -from constants import POSCAR_1_content,POSCAR_2_content,dump_conf_from_poscar +from constants import POSCAR_1_content,POSCAR_2_content,STRU1_content,dump_conf_from_poscar upload_packages.append("../fpop") upload_packages.append("./context.py") @@ -212,22 +212,26 @@ def setUp(self): self.source_path.mkdir(parents=True, exist_ok=True) self.word_path.mkdir(parents=True, exist_ok=True) - poscar_path = self.source_path / "POSCAR_tmp" - poscar_path.write_text(POSCAR_1_content) - self.confs = dpdata.System(poscar_path, fmt="vasp/poscar") - self.confs.data["spins"] = [[[1,2,3]]] + stru_path = self.source_path / "STRU_tmp" + stru_path.write_text(STRU1_content) + self.confs = dpdata.System(str(stru_path), fmt="abacus/stru") + self.confs.data["spins"] = [[[1,2,3],[4,5,6],[7,8,9],[1,1,1], + [2,2,2],[3,3,3],[4,4,4],[5,5,5]]] - (self.source_path/"INPUT").write_text('INPUT_PARAMETERS\ncalculation scf\nbasis_type lcao\nsc_mag_switch 1\n') + (self.source_path/"INPUT").write_text('INPUT_PARAMETERS\ncalculation scf\nbasis_type lcao\n') (self.source_path/"KPT").write_text('here kpt') - (self.source_path/"Na.upf").write_text('here upf') - (self.source_path/"Na.orb").write_text('here orb') + (self.source_path/"As.upf").write_text('here As upf') + (self.source_path/"Ga.upf").write_text('here Ga upf') + (self.source_path/"As.orb").write_text('here As orb') + (self.source_path/"Ga.orb").write_text('here Ga orb') (self.source_path/'optional_test').write_text('here test') self.abacus_inputs = AbacusInputs( input_file=self.source_path/"INPUT", kpt_file=self.source_path/"KPT", - pp_files={"Na":self.source_path/"Na.upf"}, - orb_files={"Na":self.source_path/"Na.orb"} + pp_files={"As":self.source_path/"As.upf","Ga":self.source_path/"Ga.upf"}, + orb_files={"As":self.source_path/"As.orb","Ga":self.source_path/"Ga.orb"}, + constrain_elements=["As"] # only constrain As ) def tearDown(self): @@ -245,15 +249,33 @@ def test_prepare_abacus_spin(self): self.assertTrue(os.path.isfile('INPUT')) self.assertTrue(os.path.isfile('KPT')) self.assertTrue(os.path.isfile('STRU')) - self.assertTrue(os.path.isfile('Na.upf')) - self.assertTrue(os.path.isfile('Na.orb')) + self.assertTrue(os.path.isfile('As.upf')) + self.assertTrue(os.path.isfile('Ga.upf')) + self.assertTrue(os.path.isfile('As.orb')) + self.assertTrue(os.path.isfile('Ga.orb')) self.assertEqual(Path('INPUT').read_text().split()[0],"INPUT_PARAMETERS") self.assertEqual(Path('KPT').read_text(),'here kpt') - self.assertEqual(Path('Na.upf').read_text(),'here upf') - self.assertEqual(Path('Na.orb').read_text(),'here orb') + self.assertEqual(Path('As.upf').read_text(),'here As upf') + self.assertEqual(Path('Ga.upf').read_text(),'here Ga upf') + self.assertEqual(Path('As.orb').read_text(),'here As orb') + self.assertEqual(Path('Ga.orb').read_text(),'here Ga orb') with open("STRU") as f : c = f.read() - self.assertTrue("0.000000000000 0.000000000000 0.000000000000 1 1 1 mag 1.000000000000 2.000000000000 3.000000000000 sc 1 1 1" in c) - + #print(c) + ref_c = '''Ga +0.0 +4 +0.000000000000 0.000000000000 0.000000000000 1 1 1 mag 1.000000000000 2.000000000000 3.000000000000 +0.000000000000 2.875074596069 2.875074596069 1 1 1 mag 4.000000000000 5.000000000000 6.000000000000 +2.875074596069 0.000000000000 2.875074596069 1 1 1 mag 7.000000000000 8.000000000000 9.000000000000 +2.875074596069 2.875074596069 0.000000000000 1 1 1 mag 1.000000000000 1.000000000000 1.000000000000 +As +0.0 +4 +1.437537298035 1.437537298035 1.437537298035 1 1 1 mag 2.000000000000 2.000000000000 2.000000000000 sc 1 1 1 +1.437537298035 4.312611894104 4.312611894104 1 1 1 mag 3.000000000000 3.000000000000 3.000000000000 sc 1 1 1 +4.312611894104 1.437537298035 4.312611894104 1 1 1 mag 4.000000000000 4.000000000000 4.000000000000 sc 1 1 1 +4.312611894104 4.312611894104 1.437537298035 1 1 1 mag 5.000000000000 5.000000000000 5.000000000000 sc 1 1 1''' + self.assertTrue(ref_c in c) os.chdir("../") From 1697b7c6bdf444f45959a442aabb597f777595e0 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 10 Oct 2024 14:25:08 +0800 Subject: [PATCH 05/11] fix pyright error --- fpop/abacus.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/fpop/abacus.py b/fpop/abacus.py index 8c83b71..7b998af 100644 --- a/fpop/abacus.py +++ b/fpop/abacus.py @@ -525,7 +525,7 @@ class PrepAbacus(PrepFp): def prep_task( self, conf_frame, - abacus_inputs: AbacusInputs, + inputs: AbacusInputs, prepare_image_config: Optional[Dict] = None, optional_input: Optional[Dict] = None, optional_artifact: Optional[Dict] = None, @@ -547,9 +547,9 @@ def prep_task( """ element_list = conf_frame['atom_names'] - pp, orb = abacus_inputs.write_pporb(element_list) - dpks = abacus_inputs.write_deepks() - mass = abacus_inputs.get_mass(element_list) + pp, orb = inputs.write_pporb(element_list) + dpks = inputs.write_deepks() + mass = inputs.get_mass(element_list) # if conf_frame has the spins, then we will use it as the initial mag and write it to STRU mag = conf_frame.data.get("spins",None) @@ -558,7 +558,7 @@ def prep_task( # if the constrain_elements is set, we will set the related flag in STRU sc = None - c_eles = abacus_inputs.get_constrain_elements() + c_eles = inputs.get_constrain_elements() if c_eles: atom_names = conf_frame.data["atom_names"] atom_types = [atom_names[i] for i in conf_frame.data["atom_types"]] @@ -566,8 +566,8 @@ def prep_task( conf_frame.to('abacus/stru', 'STRU', pp_file=pp,numerical_orbital=orb,numerical_descriptor=dpks,mass=mass,mag=mag,sc=sc) - abacus_inputs.write_input("INPUT") - abacus_inputs.write_kpt("KPT") + inputs.write_input("INPUT") + inputs.write_kpt("KPT") if optional_artifact: for file_name, file_path in optional_artifact.items(): From 4c0f0edc77901609d53218bc537df22c907e284a Mon Sep 17 00:00:00 2001 From: root Date: Thu, 10 Oct 2024 17:39:31 +0800 Subject: [PATCH 06/11] register spin in prep_fp --- fpop/prep_fp.py | 15 +++- tests/spin/deepmd-spin/set.000/box.npy | Bin 0 -> 200 bytes tests/spin/deepmd-spin/set.000/coord.npy | Bin 0 -> 152 bytes tests/spin/deepmd-spin/set.000/spin.npy | Bin 0 -> 152 bytes tests/spin/deepmd-spin/type.raw | 1 + tests/spin/deepmd-spin/type_map.raw | 1 + tests/test_prep_abacus_spin.py | 84 +++++++++++++++++++++++ 7 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 tests/spin/deepmd-spin/set.000/box.npy create mode 100644 tests/spin/deepmd-spin/set.000/coord.npy create mode 100644 tests/spin/deepmd-spin/set.000/spin.npy create mode 100644 tests/spin/deepmd-spin/type.raw create mode 100644 tests/spin/deepmd-spin/type_map.raw create mode 100644 tests/test_prep_abacus_spin.py diff --git a/fpop/prep_fp.py b/fpop/prep_fp.py index 4cf3dd5..d22e727 100644 --- a/fpop/prep_fp.py +++ b/fpop/prep_fp.py @@ -21,6 +21,7 @@ Optional, Union, ) +import dpdata class PrepFp(OP, ABC): r"""Prepares the working directories for first-principles (FP) tasks. @@ -116,7 +117,7 @@ def execute( - `task_names`: (`List[str]`) The name of tasks. Will be used as the identities of the tasks. The names of different tasks are different. - `task_paths`: (`Artifact(List[Path])`) The parepared working paths of the tasks. Contains all input files needed to start the FP. The order fo the Paths should be consistent with `op["task_names"]` """ - import dpdata + inputs = ip['inputs'] confs = ip['confs'] @@ -135,6 +136,7 @@ def execute( #System counter = 0 # loop over list of System + self._register_spin() for system in confs: ss = dpdata.System(system, fmt=conf_format, labeled=False) for ff in range(ss.get_nframes()): @@ -148,6 +150,17 @@ def execute( 'task_paths' : task_paths, }) + def _register_spin(self): + from dpdata.data_type import Axis, DataType + import numpy as np + dt = DataType( + "spins", + np.ndarray, + (Axis.NFRAMES, Axis.NATOMS, 3), + required=False, + deepmd_name="spin", + ) + dpdata.System.register_data_type(dt) def _exec_one_frame( self, diff --git a/tests/spin/deepmd-spin/set.000/box.npy b/tests/spin/deepmd-spin/set.000/box.npy new file mode 100644 index 0000000000000000000000000000000000000000..7428e80cbf53f5f3effd4864225c57f1d6b54959 GIT binary patch literal 200 zcmbR27wQ`j$;eQ~P_3SlTAW;@Zl$1ZlV+i=qoAIaUsO_*m=~X4l#&V(cT3DEP6dh= zXCxM+0{I$-ItrGWItsN4WCJeIH+B--p3Dw1_AN!b&8OPr96#E5LaN&4nAOVCo!egS lf5v_=V}l-(!?|D69yV>+u?Hsp1T6k(|B9pK#Ts@0?E&cQK==Rv literal 0 HcmV?d00001 diff --git a/tests/spin/deepmd-spin/set.000/coord.npy b/tests/spin/deepmd-spin/set.000/coord.npy new file mode 100644 index 0000000000000000000000000000000000000000..94c428e33f167cb52ab71fe7a7ccfa0643cc12e9 GIT binary patch literal 152 zcmbR27wQ`j$;eQ~P_3SlTAW;@Zl$1ZlV+i=qoAIaUsO_*m=~X4l#&V(cT3DEP6dh= aXCxM+0{I$-Its>`ItsN4WCJb+8~_07SQ~Eu literal 0 HcmV?d00001 diff --git a/tests/spin/deepmd-spin/set.000/spin.npy b/tests/spin/deepmd-spin/set.000/spin.npy new file mode 100644 index 0000000000000000000000000000000000000000..96c97f5ae32afbb3ceabee5ba8d6a51c3230ce84 GIT binary patch literal 152 zcmbR27wQ`j$;eQ~P_3SlTAW;@Zl$1ZlWC!@qoAIaUsO_*m=~X4l#&V(cT3DEP6dh= gXCxM+0{I$-Its>`ItsN4WCJcn1_)q+(#%jA0PHRscmMzZ literal 0 HcmV?d00001 diff --git a/tests/spin/deepmd-spin/type.raw b/tests/spin/deepmd-spin/type.raw new file mode 100644 index 0000000..573541a --- /dev/null +++ b/tests/spin/deepmd-spin/type.raw @@ -0,0 +1 @@ +0 diff --git a/tests/spin/deepmd-spin/type_map.raw b/tests/spin/deepmd-spin/type_map.raw new file mode 100644 index 0000000..1f7b9ab --- /dev/null +++ b/tests/spin/deepmd-spin/type_map.raw @@ -0,0 +1 @@ +Na diff --git a/tests/test_prep_abacus_spin.py b/tests/test_prep_abacus_spin.py new file mode 100644 index 0000000..55fbc87 --- /dev/null +++ b/tests/test_prep_abacus_spin.py @@ -0,0 +1,84 @@ +import os +import unittest +from dflow.python import ( + OPIO, +) + +import shutil +from pathlib import Path +from fpop.abacus import PrepAbacus,AbacusInputs + + +class TestPrepAbacus(unittest.TestCase): + ''' + deepmd/npy format named ["data.000","data.001"]. + no optional_input or optional_artifact. + ''' + def setUp(self): + # config in spin/deepmd-spin is contants.POSCAR_1_content, and add spins = [[[1,2,3]]] + # here to test if prep_fp can read the spins data. + self.confs = [Path("spin/deepmd-spin")] + self.ntasks = len(self.confs) + self.type_map = ['Na'] + + self.source_path = Path('abacustest') + self.source_path.mkdir(parents=True, exist_ok=True) + (self.source_path/"INPUT").write_text('INPUT_PARAMETERS\ncalculation scf\nbasis_type lcao\n') + (self.source_path/"KPT").write_text('here kpt') + (self.source_path/"Na.upf").write_text('here upf') + (self.source_path/"Na.orb").write_text('here orb') + (self.source_path/'optional_test').write_text('here test') + + self.abacus_inputs = AbacusInputs( + input_file=self.source_path/"INPUT", + kpt_file=self.source_path/"KPT", + pp_files={"Na":self.source_path/"Na.upf"}, + orb_files={"Na":self.source_path/"Na.orb"} + ) + + def tearDown(self): + for ii in range(self.ntasks): + work_path = Path("task.%06d"%ii) + if work_path.is_dir(): + shutil.rmtree(work_path) + if os.path.isdir(self.source_path): + shutil.rmtree(self.source_path) + + def checkfile(self): + tdir = "task.000000" + print(tdir) + self.assertTrue(Path(tdir).is_dir()) + self.assertTrue(os.path.isfile(Path(tdir)/'INPUT')) + self.assertTrue(os.path.isfile(Path(tdir)/'KPT')) + self.assertTrue(os.path.isfile(Path(tdir)/'STRU')) + self.assertTrue(os.path.isfile(Path(tdir)/'Na.upf')) + self.assertTrue(os.path.isfile(Path(tdir)/'Na.orb')) + self.assertEqual((Path(tdir)/'INPUT').read_text().split()[0],"INPUT_PARAMETERS") + self.assertEqual((Path(tdir)/'KPT').read_text(),'here kpt') + self.assertEqual((Path(tdir)/'Na.upf').read_text(),'here upf') + self.assertEqual((Path(tdir)/'Na.orb').read_text(),'here orb') + stru_c = (Path(tdir)/'STRU').read_text() + self.assertTrue("0.000000000000 0.000000000000 0.000000000000 1 1 1 mag 1.000000000000 2.000000000000 3.000000000000" in stru_c) + return [tdir] + + def test_prepare(self): + op = PrepAbacus() + out = op.execute( + OPIO( + { + "prep_image_config" : {}, + "optional_artifact" : {"TEST": (self.source_path/'optional_test').absolute()}, + "confs" : self.confs, + "inputs" : self.abacus_inputs, + "type_map" : self.type_map, + } + ) + ) + + tdirs = self.checkfile() + + self.assertEqual(tdirs, out['task_names']) + self.assertEqual(tdirs, [str(ii) for ii in out['task_paths']]) + + for ii in out['task_names']: + self.assertEqual(Path(Path(ii)/'TEST').read_text(), "here test") From 0cb066ec0f42132f8f943af0bfe2713d95585739 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 15 Oct 2024 16:28:44 +0800 Subject: [PATCH 07/11] always prepare orb files no matter if is LCAO job --- fpop/abacus.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/fpop/abacus.py b/fpop/abacus.py index 7b998af..0b6b9ce 100644 --- a/fpop/abacus.py +++ b/fpop/abacus.py @@ -454,21 +454,15 @@ def write_pporb(self,element_list : List[str]): List[List] a list of the list of pp files, and orbital files """ - need_orb = False - if self._input.get("basis_type","pw").lower() in ["lcao","lcao_in_pw"]: - need_orb = True pp,orb = [],[] for ielement in element_list: if ielement in self._pp_files: Path(self._pp_files[ielement][0]).write_text(self._pp_files[ielement][1]) pp.append(self._pp_files[ielement][0]) - if need_orb and ielement in self._orb_files: + if ielement in self._orb_files: Path(self._orb_files[ielement][0]).write_text(self._orb_files[ielement][1]) orb.append(self._orb_files[ielement][0]) - if not orb: - orb = None - return [pp,orb] def write_deepks(self): From 42bb34db74cd0282e991e821dc225760a511bf8a Mon Sep 17 00:00:00 2001 From: root Date: Wed, 16 Oct 2024 18:15:18 +0800 Subject: [PATCH 08/11] fix test --- tests/test_abacus_inputs.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/test_abacus_inputs.py b/tests/test_abacus_inputs.py index 1a58399..be87c0d 100644 --- a/tests/test_abacus_inputs.py +++ b/tests/test_abacus_inputs.py @@ -43,7 +43,7 @@ def test_writefile1(self): self.assertTrue(os.path.isfile("KPT")) self.assertTrue(os.path.isfile("H.upf")) self.assertFalse(os.path.isfile("O.upf")) - self.assertFalse(os.path.isfile("H.orb")) + self.assertTrue(os.path.isfile("H.orb")) self.assertFalse(os.path.isfile("O.orb")) self.assertEqual("INPUT_PARAMETERS", Path("INPUT").read_text().split("\n")[0]) @@ -52,6 +52,7 @@ def test_writefile1(self): self.assertEqual(Path("KPT").read_text(),"tkpt") self.assertEqual(Path("H.upf").read_text(),"tH.upf") + self.assertEqual(Path("H.orb").read_text(),"tH.orb") def test_writefile2(self): abacusinput = AbacusInputs(input_file="../INPUT", @@ -67,8 +68,8 @@ def test_writefile2(self): self.assertTrue(os.path.isfile("KPT")) self.assertTrue(os.path.isfile("H.upf")) self.assertTrue(os.path.isfile("O.upf")) - self.assertFalse(os.path.isfile("H.orb")) - self.assertFalse(os.path.isfile("O.orb")) + self.assertTrue(os.path.isfile("H.orb")) + self.assertTrue(os.path.isfile("O.orb")) def test_writefile3(self): abacusinput = AbacusInputs(input_file="../INPUT", From 1421e25c45ced024841500d2bae133baa46052c2 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 30 Apr 2025 11:52:53 +0800 Subject: [PATCH 09/11] fix bug in execute --- fpop/abacus.py | 2 +- fpop/run_fp.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/fpop/abacus.py b/fpop/abacus.py index 0b6b9ce..41a2cbf 100644 --- a/fpop/abacus.py +++ b/fpop/abacus.py @@ -648,7 +648,7 @@ def run_task( command = "abacus" # run abacus command = " ".join([command, ">", log_name]) - ret, out, err = run_command(command, raise_error=False, try_bash=True,) + ret, out, err = run_command(command, raise_error=False, shell=True,) if ret != 0: raise TransientError( "abacus failed\n", "out msg", out, "\n", "err msg", err, "\n" diff --git a/fpop/run_fp.py b/fpop/run_fp.py index 87ac1c3..798d552 100644 --- a/fpop/run_fp.py +++ b/fpop/run_fp.py @@ -162,10 +162,18 @@ def execute( if not os.path.exists(ii): raise FatalError(f"cannot file file/directory {ii}") iname = ii.name + if os.path.isfile(iname): + os.remove(iname) + elif os.path.isdir(iname): + shutil.rmtree(iname) Path(iname).symlink_to(ii) for ii in opt_input_files: if os.path.exists(ii): iname = ii.name + if os.path.isfile(iname): + os.remove(iname) + elif os.path.isdir(iname): + shutil.rmtree(iname) Path(iname).symlink_to(ii) backward_dir_name = self.run_task(backward_dir_name,log_name,backward_list,run_image_config,optional_input) From 7d5a5679dbd3578a72347b18ce247d21700b4985 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 30 Apr 2025 17:22:14 +0800 Subject: [PATCH 10/11] do not check if abacus job is normal ending --- fpop/abacus.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fpop/abacus.py b/fpop/abacus.py index 41a2cbf..ef1e6dd 100644 --- a/fpop/abacus.py +++ b/fpop/abacus.py @@ -653,10 +653,10 @@ def run_task( raise TransientError( "abacus failed\n", "out msg", out, "\n", "err msg", err, "\n" ) - if not self.check_run_success(log_name): - raise TransientError( - "abacus failed , we could not check the exact cause . Please check log file ." - ) + #if not self.check_run_success(log_name): + # raise TransientError( + # "abacus failed , we could not check the exact cause . Please check log file ." + # ) os.makedirs(Path(backward_dir_name)) shutil.copyfile(log_name,Path(backward_dir_name)/log_name) for ii in backward_list: From 0c7430441925bb413abd9bd6d1889f648bcafecd Mon Sep 17 00:00:00 2001 From: root Date: Sat, 3 May 2025 21:30:08 +0800 Subject: [PATCH 11/11] add the check of backward_dir_name in RunAbacus.run_task() --- fpop/abacus.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fpop/abacus.py b/fpop/abacus.py index ef1e6dd..696fef3 100644 --- a/fpop/abacus.py +++ b/fpop/abacus.py @@ -657,6 +657,8 @@ def run_task( # raise TransientError( # "abacus failed , we could not check the exact cause . Please check log file ." # ) + if os.path.isdir(backward_dir_name): + shutil.rmtree(backward_dir_name) os.makedirs(Path(backward_dir_name)) shutil.copyfile(log_name,Path(backward_dir_name)/log_name) for ii in backward_list: