Skip to content

Commit

Permalink
Merge pull request #5 from deepmodeling/devel
Browse files Browse the repository at this point in the history
Devel update
  • Loading branch information
iProzd committed Apr 20, 2021
2 parents 7feb3a4 + 4b5e916 commit 7374920
Show file tree
Hide file tree
Showing 12 changed files with 770 additions and 470 deletions.
16 changes: 8 additions & 8 deletions deepmd/descriptor/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from .hybrid import DescrptHybrid
from .se_a import DescrptSeA
from .se_r import DescrptSeR
from .se_ar import DescrptSeAR
from .se_a_t import DescrptSeAT
from .se_a_ebd import DescrptSeAEbd
from .se_a_ef import DescrptSeAEf
from .se_a_ef import DescrptSeAEfLower
from .hybrid import DescrptHybrid
from .se_a import DescrptSeA
from .se_r import DescrptSeR
from .se_ar import DescrptSeAR
from .se_t import DescrptSeT
from .se_a_ebd import DescrptSeAEbd
from .se_a_ef import DescrptSeAEf
from .se_a_ef import DescrptSeAEfLower
from .loc_frame import DescrptLocFrame
14 changes: 7 additions & 7 deletions deepmd/descriptor/hybrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
from deepmd.env import GLOBAL_NP_FLOAT_PRECISION
# from deepmd.descriptor import DescrptLocFrame
# from deepmd.descriptor import DescrptSeA
# from deepmd.descriptor import DescrptSeAT
# from deepmd.descriptor import DescrptSeT
# from deepmd.descriptor import DescrptSeAEbd
# from deepmd.descriptor import DescrptSeAEf
# from deepmd.descriptor import DescrptSeR
from .se_a import DescrptSeA
from .se_r import DescrptSeR
from .se_ar import DescrptSeAR
from .se_a_t import DescrptSeAT
from .se_a_ebd import DescrptSeAEbd
from .se_a_ef import DescrptSeAEf
from .se_a import DescrptSeA
from .se_r import DescrptSeR
from .se_ar import DescrptSeAR
from .se_t import DescrptSeT
from .se_a_ebd import DescrptSeAEbd
from .se_a_ef import DescrptSeAEf
from .loc_frame import DescrptLocFrame

class DescrptHybrid ():
Expand Down
6 changes: 3 additions & 3 deletions deepmd/descriptor/se_a_t.py → deepmd/descriptor/se_t.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from deepmd.env import default_tf_session_config
from deepmd.utils.network import embedding_net

class DescrptSeAT ():
class DescrptSeT ():
@docstring_parameter(list_to_doc(ACTIVATION_FN_DICT.keys()), list_to_doc(PRECISION_DICT.keys()))
def __init__ (self,
rcut: float,
Expand Down Expand Up @@ -95,7 +95,7 @@ def __init__ (self,
self.place_holders['natoms_vec'] = tf.placeholder(tf.int32, [self.ntypes+2], name=name_pfx+'t_natoms')
self.place_holders['default_mesh'] = tf.placeholder(tf.int32, [None], name=name_pfx+'t_mesh')
self.stat_descrpt, descrpt_deriv, rij, nlist \
= op_module.descrpt_se_a(self.place_holders['coord'],
= op_module.prod_env_mat_a(self.place_holders['coord'],
self.place_holders['type'],
self.place_holders['natoms_vec'],
self.place_holders['box'],
Expand Down Expand Up @@ -282,7 +282,7 @@ def build (self,
atype = tf.reshape (atype_, [-1, natoms[1]])

self.descrpt, self.descrpt_deriv, self.rij, self.nlist \
= op_module.descrpt_se_a (coord,
= op_module.prod_env_mat_a (coord,
atype,
natoms,
box,
Expand Down
5 changes: 2 additions & 3 deletions deepmd/entrypoints/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from deepmd.train.run_options import BUILD, CITATION, WELCOME, RunOptions
from deepmd.train.trainer import DPTrainer
from deepmd.utils.argcheck import normalize
from deepmd.utils.compat import convert_input_v0_v1
from deepmd.utils.compat import updata_deepmd_input
from deepmd.utils.data_system import DeepmdDataSystem

if TYPE_CHECKING:
Expand Down Expand Up @@ -168,8 +168,7 @@ def train(
# load json database
jdata = j_loader(INPUT)

if "model" not in jdata.keys():
jdata = convert_input_v0_v1(jdata, warning=True, dump="input_v1_compat.json")
jdata = updata_deepmd_input(jdata, warning=True, dump="input_v2_compat.json")

jdata = normalize(jdata)
with open(output, "w") as fp:
Expand Down
14 changes: 7 additions & 7 deletions deepmd/train/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from deepmd.fit import EnerFitting, WFCFitting, PolarFittingLocFrame, PolarFittingSeA, GlobalPolarFittingSeA, DipoleFittingSeA
from deepmd.descriptor import DescrptLocFrame
from deepmd.descriptor import DescrptSeA
from deepmd.descriptor import DescrptSeAT
from deepmd.descriptor import DescrptSeT
from deepmd.descriptor import DescrptSeAEbd
from deepmd.descriptor import DescrptSeAEf
from deepmd.descriptor import DescrptSeR
Expand Down Expand Up @@ -55,16 +55,16 @@ def _generate_descrpt_from_param_dict(descrpt_param):
descrpt_param.pop(kk, None)
if descrpt_type == 'loc_frame':
descrpt = DescrptLocFrame(**descrpt_param)
elif descrpt_type == 'se_a' :
elif descrpt_type == 'se_e2_a' or descrpt_type == 'se_a' :
descrpt = DescrptSeA(**descrpt_param)
elif descrpt_type == 'se_a_3be' or descrpt_type == 'se_at' :
descrpt = DescrptSeAT(**descrpt_param)
elif descrpt_type == 'se_e2_r' or descrpt_type == 'se_r' :
descrpt = DescrptSeR(**descrpt_param)
elif descrpt_type == 'se_e3' or descrpt_type == 'se_at' or descrpt_type == 'se_a_3be' :
descrpt = DescrptSeT(**descrpt_param)
elif descrpt_type == 'se_a_tpe' or descrpt_type == 'se_a_ebd' :
descrpt = DescrptSeAEbd(**descrpt_param)
elif descrpt_type == 'se_a_ef' :
descrpt = DescrptSeAEf(**descrpt_param)
elif descrpt_type == 'se_r' :
descrpt = DescrptSeR(**descrpt_param)
elif descrpt_type == 'se_ar' :
descrpt = DescrptSeAR(descrpt_param)
else :
Expand Down Expand Up @@ -568,7 +568,7 @@ def valid_on_the_fly(self,
@staticmethod
def print_header(fp, train_results, valid_results):
print_str = ''
print_str += "# %5s" % 'batch'
print_str += "# %5s" % 'step'
if valid_results is not None:
prop_fmt = ' %11s %11s'
for k in train_results.keys():
Expand Down
34 changes: 24 additions & 10 deletions deepmd/utils/argcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def descrpt_se_a_args():
]


def descrpt_se_a_3be_args():
def descrpt_se_t_args():
doc_sel = 'A list of integers. The length of the list should be the same as the number of atom types in the system. `sel[i]` gives the selected number of type-i neighbors. `sel[i]` is recommended to be larger than the maximally possible number of type-i neighbors in the cut-off radius.'
doc_rcut = 'The cut-off radius.'
doc_rcut_smth = 'Where to start smoothing. For example the 1/r term is smoothed from `rcut` to `rcut_smth`'
Expand Down Expand Up @@ -162,24 +162,24 @@ def descrpt_hybrid_args():

def descrpt_variant_type_args():
link_lf = make_link('loc_frame', 'model/descriptor[loc_frame]')
link_se_a = make_link('se_a', 'model/descriptor[se_a]')
link_se_r = make_link('se_r', 'model/descriptor[se_r]')
link_se_a_3be = make_link('se_a_3be', 'model/descriptor[se_a_3be]')
link_se_e2_a = make_link('se_e2_a', 'model/descriptor[se_e2_a]')
link_se_e2_r = make_link('se_e2_r', 'model/descriptor[se_e2_r]')
link_se_e3 = make_link('se_e3', 'model/descriptor[se_e3]')
link_se_a_tpe = make_link('se_a_tpe', 'model/descriptor[se_a_tpe]')
link_hybrid = make_link('hybrid', 'model/descriptor[hybrid]')
doc_descrpt_type = f'The type of the descritpor. See explanation below. \n\n\
- `loc_frame`: Defines a local frame at each atom, and the compute the descriptor as local coordinates under this frame.\n\n\
- `se_a`: Used by the smooth edition of Deep Potential. The full relative coordinates are used to construct the descriptor.\n\n\
- `se_r`: Used by the smooth edition of Deep Potential. Only the distance between atoms is used to construct the descriptor.\n\n\
- `se_a_3be`: Used by the smooth edition of Deep Potential. The full relative coordinates are used to construct the descriptor. Three-body embedding will be used by this descriptor.\n\n\
- `se_e2_a`: Used by the smooth edition of Deep Potential. The full relative coordinates are used to construct the descriptor.\n\n\
- `se_e2_r`: Used by the smooth edition of Deep Potential. Only the distance between atoms is used to construct the descriptor.\n\n\
- `se_e3`: Used by the smooth edition of Deep Potential. The full relative coordinates are used to construct the descriptor. Three-body embedding will be used by this descriptor.\n\n\
- `se_a_tpe`: Used by the smooth edition of Deep Potential. The full relative coordinates are used to construct the descriptor. Type embedding will be used by this descriptor.\n\n\
- `hybrid`: Concatenate of a list of descriptors as a new descriptor.'

return Variant("type", [
Argument("loc_frame", dict, descrpt_local_frame_args()),
Argument("se_a", dict, descrpt_se_a_args()),
Argument("se_r", dict, descrpt_se_r_args()),
Argument("se_a_3be", dict, descrpt_se_a_3be_args(), alias = ['se_at']),
Argument("se_e2_a", dict, descrpt_se_a_args(), alias = ['se_a']),
Argument("se_e2_r", dict, descrpt_se_r_args(), alias = ['se_r']),
Argument("se_e3", dict, descrpt_se_t_args(), alias = ['se_at', 'se_a_3be', 'se_t']),
Argument("se_a_tpe", dict, descrpt_se_a_tpe_args(), alias = ['se_a_ebd']),
Argument("hybrid", dict, descrpt_hybrid_args()),
], doc = doc_descrpt_type)
Expand Down Expand Up @@ -553,7 +553,21 @@ def gen_doc(*, make_anchor=True, make_link=True, **kwargs):
return "\n\n".join(ptr)


def normalize_hybrid_list(hy_list):
new_list = []
base = Argument("base", dict, [], [descrpt_variant_type_args()], doc = "")
for ii in range(len(hy_list)):
data = base.normalize_value(hy_list[ii], trim_pattern="_*")
base.check_value(data, strict=True)
new_list.append(data)
return new_list


def normalize(data):
if "hybrid" == data["model"]["descriptor"]["type"]:
data["model"]["descriptor"]["list"] \
= normalize_hybrid_list(data["model"]["descriptor"]["list"])

ma = model_args()
lra = learning_rate_args()
la = loss_args()
Expand Down
Loading

0 comments on commit 7374920

Please sign in to comment.