Skip to content

refactor(abacus): modify poscar2stru in auto_test.lib.abacus #1193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 25, 2023
Merged
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
23 changes: 16 additions & 7 deletions dpgen/auto_test/lib/abacus.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

import dpdata
import numpy as np
from dpdata.abacus.scf import make_unlabeled_stru
from dpdata.utils import uniq_atom_names
from dpdata.vasp import poscar as dpdata_poscar
from pymatgen.core.structure import Structure

import dpgen.generator.lib.abacus_scf as abacus_scf
Expand Down Expand Up @@ -242,7 +245,7 @@
]


def poscar2stru(poscar, inter_param, stru):
def poscar2stru(poscar, inter_param, stru="STRU"):
"""
- poscar: POSCAR for input
- inter_param: dictionary of 'interaction' from param.json
Expand All @@ -252,8 +255,12 @@ def poscar2stru(poscar, inter_param, stru):
- deepks_desc: a string of deepks descriptor file
- stru: output filename, usally is 'STRU'
"""
stru = dpdata.System(poscar, fmt="vasp/poscar")
stru_data = stru.data
# if use dpdata.System, the structure will be rotated to make cell to be lower triangular
with open(poscar) as fp:
lines = [line.rstrip("\n") for line in fp]
stru_data = dpdata_poscar.to_system_data(lines)
stru_data = uniq_atom_names(stru_data)

atom_mass = []
pseudo = None
orb = None
Expand Down Expand Up @@ -291,14 +298,16 @@ def poscar2stru(poscar, inter_param, stru):
if "deepks_desc" in inter_param:
deepks_desc = "./pp_orb/%s\n" % inter_param["deepks_desc"]

stru.to(
"stru",
"STRU",
mass=atom_mass,
stru_string = make_unlabeled_stru(
data=stru_data,
frame_idx=0,
pp_file=pseudo,
numerical_orbital=orb,
numerical_descriptor=deepks_desc,
mass=atom_mass,
)
with open(stru, "w") as fp:
fp.write(stru_string)


def stru_fix_atom(struf, fix_atom=[True, True, True]):
Expand Down