Skip to content

Commit

Permalink
Merge pull request #258 from deepmodeling/r1.2
Browse files Browse the repository at this point in the history
merge R1.2 bug fixings to master
  • Loading branch information
amcadmus authored Sep 17, 2020
2 parents 30922e7 + e110ec4 commit 59d780c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
11 changes: 5 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
from setuptools_scm import get_version
from packaging.version import LegacyVersion
from os import path, makedirs
import imp, sys, platform
import os, imp, sys, platform, sysconfig

def get_dp_install_path() :
site_packages_path = path.join(path.dirname(path.__file__), 'site-packages')
dp_scm_version = get_version(root="./", relative_to=__file__)
site_packages_path = sysconfig.get_paths()['purelib']
dp_scm_version = get_version(root=".", relative_to=__file__)
python_version = 'py' + str(sys.version_info.major + sys.version_info.minor * 0.1)
os_info = sys.platform
machine_info = platform.machine()
dp_pip_install_path = site_packages_path + '/deepmd'
dp_setup_install_path = site_packages_path + '/deepmd_kit-' + dp_scm_version + '-' + python_version + '-' + os_info + '-' + machine_info + '.egg/deepmd'

dp_pip_install_path = os.path.join(site_packages_path, 'deepmd')
dp_setup_install_path = os.path.join(site_packages_path, 'deepmd_kit-' + dp_scm_version + '-' + python_version + '-' + os_info + '-' + machine_info + '.egg', 'deepmd')
return dp_pip_install_path, dp_setup_install_path

readme_file = path.join(path.dirname(path.abspath(__file__)), 'README.md')
Expand Down
7 changes: 4 additions & 3 deletions source/train/Loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,12 @@ def build (self,
polar_hat = label_dict[self.label_name]
polar = model_dict[self.tensor_name]
l2_loss = tf.reduce_mean( tf.square(self.scale*(polar - polar_hat)), name='l2_'+suffix)
more_loss = {'nonorm': l2_loss}
if not self.atomic :
atom_norm = 1./ global_cvt_2_tf_float(natoms[0])
l2_loss = l2_loss * atom_norm
self.l2_l = l2_loss
more_loss = {}
self.l2_more = more_loss['nonorm']

return l2_loss, more_loss

Expand All @@ -321,10 +322,10 @@ def print_on_training(self,
feed_dict_test,
feed_dict_batch) :
error_test\
= sess.run([self.l2_l], \
= sess.run([self.l2_more], \
feed_dict=feed_dict_test)
error_train\
= sess.run([self.l2_l], \
= sess.run([self.l2_more], \
feed_dict=feed_dict_batch)
print_str = ""
prop_fmt = " %9.2e %9.2e"
Expand Down
27 changes: 23 additions & 4 deletions source/train/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from deepmd import DeepPot
from deepmd import DeepDipole
from deepmd import DeepPolar
from deepmd import DeepGlobalPolar
from deepmd import DeepWFC
from tensorflow.python.framework import ops

Expand All @@ -28,6 +29,8 @@ def test (args):
dp = DeepDipole(args.model)
elif de.model_type == 'polar':
dp = DeepPolar(args.model)
elif de.model_type == 'global_polar':
dp = DeepGlobalPolar(args.model)
elif de.model_type == 'wfc':
dp = DeepWFC(args.model)
else :
Expand All @@ -41,7 +44,9 @@ def test (args):
elif de.model_type == 'dipole':
err, siz = test_dipole(dp, args)
elif de.model_type == 'polar':
err, siz = test_polar(dp, args)
err, siz = test_polar(dp, args, global_polar=False)
elif de.model_type == 'global_polar':
err, siz = test_polar(dp, args, global_polar=True)
elif de.model_type == 'wfc':
err, siz = test_wfc(dp, args)
else :
Expand All @@ -61,6 +66,8 @@ def test (args):
print_dipole_sys_avg(avg_err)
elif de.model_type == 'polar':
print_polar_sys_avg(avg_err)
elif de.model_type == 'global_polar':
print_polar_sys_avg(avg_err)
elif de.model_type == 'wfc':
print_wfc_sys_avg(avg_err)
else :
Expand Down Expand Up @@ -223,12 +230,15 @@ def print_wfc_sys_avg(avg):
print ("WFC L2err : %e eV/A" % avg[0])


def test_polar (dp, args) :
def test_polar (dp, args, global_polar = False) :
if args.rand_seed is not None :
np.random.seed(args.rand_seed % (2**32))

data = DeepmdData(args.system, args.set_prefix, shuffle_test = args.shuffle_test)
data.add('polarizability', 9, atomic=True, must=True, high_prec=False, type_sel = dp.get_sel_type())
if not global_polar:
data.add('polarizability', 9, atomic=True, must=True, high_prec=False, type_sel = dp.get_sel_type())
else:
data.add('polarizability', 9, atomic=False, must=True, high_prec=False, type_sel = dp.get_sel_type())
test_data = data.get_test ()
numb_test = args.numb_test
natoms = len(test_data["type"][0])
Expand All @@ -239,12 +249,21 @@ def test_polar (dp, args) :
box = test_data["box"][:numb_test]
atype = test_data["type"][0]
polar = dp.eval(coord, box, atype)
sel_type = dp.get_sel_type()
sel_natoms = 0
for ii in sel_type:
sel_natoms += sum(atype == ii)

polar = polar.reshape([numb_test,-1])
l2f = (l2err (polar - test_data["polarizability"] [:numb_test]))
l2fs = l2f/np.sqrt(sel_natoms)
l2fa = l2f/sel_natoms

print ("# number of test data : %d " % numb_test)
print ("Polarizability L2err : %e eV/A" % l2f)
print ("Polarizability L2err : %e eV/A" % l2f)
if global_polar:
print ("Polarizability L2err/sqrtN : %e eV/A" % l2fs)
print ("Polarizability L2err/N : %e eV/A" % l2fa)

detail_file = args.detail_file
if detail_file is not None :
Expand Down

0 comments on commit 59d780c

Please sign in to comment.