Exemplo n.º 1
0
 def setUp(self, data, pbc=True):
     self.sess = tf.Session()
     self.data = data
     self.natoms = self.data.get_natoms()
     self.ntypes = self.data.get_ntypes()
     self.sel = [12, 24]
     self.sel_a = [0, 0]
     self.rcut_smth = 2.45
     self.rcut = 10.0
     self.nnei = np.cumsum(self.sel)[-1]
     self.ndescrpt = self.nnei * 1
     davg = np.zeros([self.ntypes, self.ndescrpt])
     dstd = np.ones([self.ntypes, self.ndescrpt])
     self.t_avg = tf.constant(davg.astype(global_np_float_precision))
     self.t_std = tf.constant(dstd.astype(global_np_float_precision))
     if pbc:
         self.default_mesh = np.zeros(6, dtype=np.int32)
         self.default_mesh[3] = 2
         self.default_mesh[4] = 2
         self.default_mesh[5] = 2
     else:
         self.default_mesh = np.array([], dtype=np.int32)
     # make place holder
     self.coord = tf.placeholder(global_tf_float_precision,
                                 [None, self.natoms[0] * 3],
                                 name='t_coord')
     self.box = tf.placeholder(global_tf_float_precision, [None, 9],
                               name='t_box')
     self.type = tf.placeholder(tf.int32, [None, self.natoms[0]],
                                name="t_type")
     self.tnatoms = tf.placeholder(tf.int32, [None], name="t_natoms")
Exemplo n.º 2
0
 def setUp(self, data, pbc=True, sess=None):
     self.sess = sess
     self.data = data
     self.natoms = self.data.get_natoms()
     self.ntypes = self.data.get_ntypes()
     self.sel = [12, 24]
     self.sel_a = [0, 0]
     self.rcut_smth = 2.45
     self.rcut = 10.0
     self.nnei = np.cumsum(self.sel)[-1]
     self.ndescrpt = self.nnei * 1
     davg = np.zeros([self.ntypes, self.ndescrpt])
     dstd = np.ones([self.ntypes, self.ndescrpt])
     self.t_avg = tf.constant(davg.astype(GLOBAL_NP_FLOAT_PRECISION))
     self.t_std = tf.constant(dstd.astype(GLOBAL_NP_FLOAT_PRECISION))
     if pbc:
         self.default_mesh = np.zeros(6, dtype=np.int32)
         self.default_mesh[3] = 2
         self.default_mesh[4] = 2
         self.default_mesh[5] = 2
     else:
         self.default_mesh = np.array([], dtype=np.int32)
     # make place holder
     self.coord = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION,
                                 [None, self.natoms[0] * 3],
                                 name='t_coord')
     self.box = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None, 9],
                               name='t_box')
     self.type = tf.placeholder(tf.int32, [None, self.natoms[0]],
                                name="t_type")
     self.tnatoms = tf.placeholder(tf.int32, [None], name="t_natoms")
     self.efield = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION,
                                  [None, self.natoms[0] * 3],
                                  name='t_efield')
Exemplo n.º 3
0
 def setUp(self):
     self.sess = self.test_session().__enter__()
     self.natoms = [5, 5, 2, 3]
     self.ntypes = 2
     self.sel_a = [12, 24]
     self.sel_r = [0, 0]
     self.rcut_a = -1
     self.rcut_r_smth = 2.45
     self.rcut_r = 10.0
     self.nnei_a = np.cumsum(self.sel_a)[-1]
     self.nnei_r = np.cumsum(self.sel_r)[-1]
     self.nnei = self.nnei_a + self.nnei_r
     self.ndescrpt_a = self.nnei_a * 4
     self.ndescrpt_r = self.nnei_r * 1
     self.ndescrpt = self.ndescrpt_a + self.ndescrpt_r
     davg = np.zeros([self.ntypes, self.ndescrpt])
     dstd = np.ones([self.ntypes, self.ndescrpt])
     self.t_avg = tf.constant(davg.astype(GLOBAL_NP_FLOAT_PRECISION))
     self.t_std = tf.constant(dstd.astype(GLOBAL_NP_FLOAT_PRECISION))
     # no pbc
     self.default_mesh = np.array([], dtype=np.int32)
     # make place holder
     self.coord = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION,
                                 [None, self.natoms[0] * 3],
                                 name='t_coord')
     self.efield = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION,
                                  [None, self.natoms[0] * 3],
                                  name='t_efield')
     self.box = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None, 9],
                               name='t_box')
     self.type = tf.placeholder(tf.int32, [None, self.natoms[0]],
                                name="t_type")
     self.tnatoms = tf.placeholder(tf.int32, [None], name="t_natoms")
 def __init__(self, data, comp=0):
     self.sess = tf.Session()
     self.data = data
     self.natoms = self.data.get_natoms()
     self.ntypes = self.data.get_ntypes()
     self.sel_a = [12, 24]
     self.sel_r = [12, 24]
     self.rcut_a = -1
     self.rcut_r = 10.0
     self.axis_rule = [0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0]
     self.nnei_a = np.cumsum(self.sel_a)[-1]
     self.nnei_r = np.cumsum(self.sel_r)[-1]
     self.nnei = self.nnei_a + self.nnei_r
     self.ndescrpt_a = self.nnei_a * 4
     self.ndescrpt_r = self.nnei_r * 1
     self.ndescrpt = self.ndescrpt_a + self.ndescrpt_r
     davg = np.zeros([self.ntypes, self.ndescrpt])
     dstd = np.ones([self.ntypes, self.ndescrpt])
     self.t_avg = tf.constant(davg.astype(global_np_float_precision))
     self.t_std = tf.constant(dstd.astype(global_np_float_precision))
     self.default_mesh = np.zeros(6, dtype=np.int32)
     self.default_mesh[3] = 2
     self.default_mesh[4] = 2
     self.default_mesh[5] = 2
     # make place holder
     self.coord = tf.placeholder(global_tf_float_precision,
                                 [None, self.natoms[0] * 3],
                                 name='t_coord')
     self.box = tf.placeholder(global_tf_float_precision, [None, 9],
                               name='t_box')
     self.type = tf.placeholder(tf.int32, [None, self.natoms[0]],
                                name="t_type")
     self.tnatoms = tf.placeholder(tf.int32, [None], name="t_natoms")
Exemplo n.º 5
0
    def __init__(self, hh, beta):
        """
        Constructor 

        Parameters
        ----------
        hh
                Grid spacing of the reciprocal part of Ewald sum. Unit: A
        beta
                Splitting parameter of the Ewald sum. Unit: A^{-1}
        """
        self.hh = hh
        self.beta = beta
        with tf.Graph().as_default() as graph:
            # place holders
            self.t_nloc = tf.placeholder(tf.int32, [1], name="t_nloc")
            self.t_coord = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None],
                                          name='t_coord')
            self.t_charge = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None],
                                           name='t_charge')
            self.t_box = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None],
                                        name='t_box')
            # output
            self.t_energy, self.t_force, self.t_virial \
                = op_module.ewald_recp(self.t_coord, self.t_charge, self.t_nloc, self.t_box,
                                       ewald_h = self.hh,
                                       ewald_beta = self.beta)
        self.sess = tf.Session(graph=graph, config=default_tf_session_config)
Exemplo n.º 6
0
    def _build_network(self, data):        
        self.place_holders = {}
        if self.is_compress :
            for kk in ['coord', 'box']:
                self.place_holders[kk] = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None], 't_' + kk)
            self._get_place_horders(data_requirement)
        else :
            self._get_place_horders(data.get_data_dict())

        self.place_holders['type']      = tf.placeholder(tf.int32,   [None], name='t_type')
        self.place_holders['natoms_vec']        = tf.placeholder(tf.int32,   [self.ntypes+2], name='t_natoms')
        self.place_holders['default_mesh']      = tf.placeholder(tf.int32,   [None], name='t_mesh')
        self.place_holders['is_training']       = tf.placeholder(tf.bool)
        self.model_pred\
            = self.model.build (self.place_holders['coord'], 
                                self.place_holders['type'], 
                                self.place_holders['natoms_vec'], 
                                self.place_holders['box'], 
                                self.place_holders['default_mesh'],
                                self.place_holders,
                                self.frz_model,
                                suffix = "", 
                                reuse = False)

        self.l2_l, self.l2_more\
            = self.loss.build (self.learning_rate,
                               self.place_holders['natoms_vec'], 
                               self.model_pred,
                               self.place_holders,
                               suffix = "test")

        log.info("built network")
Exemplo n.º 7
0
 def __init__(self, ntypes: int, rcut: float) -> None:
     """
     Constructor
     """
     self.rcut = rcut
     self.ntypes = ntypes
     self.place_holders = {}
     sub_graph = tf.Graph()
     with sub_graph.as_default():
         for ii in ['coord', 'box']:
             self.place_holders[ii] = tf.placeholder(
                 GLOBAL_NP_FLOAT_PRECISION, [None, None], name='t_' + ii)
         self.place_holders['type'] = tf.placeholder(tf.int32, [None, None],
                                                     name='t_type')
         self.place_holders['natoms_vec'] = tf.placeholder(
             tf.int32, [self.ntypes + 2], name='t_natoms')
         self.place_holders['default_mesh'] = tf.placeholder(tf.int32,
                                                             [None],
                                                             name='t_mesh')
         self._max_nbor_size, self._min_nbor_dist \
             = op_module.neighbor_stat(self.place_holders['coord'],
                                      self.place_holders['type'],
                                      self.place_holders['natoms_vec'],
                                      self.place_holders['box'],
                                      self.place_holders['default_mesh'],
                                      rcut = self.rcut)
     self.sub_sess = tf.Session(graph=sub_graph,
                                config=default_tf_session_config)
Exemplo n.º 8
0
    def __init__(self, 
                 rcut: float,
                 sel_a : List[int],
                 sel_r : List[int],
                 axis_rule : List[int]
    ) -> None:
        """
        Constructor    
        """
        # args = ClassArg()\
        #        .add('sel_a',    list,   must = True) \
        #        .add('sel_r',    list,   must = True) \
        #        .add('rcut',     float,  default = 6.0) \
        #        .add('axis_rule',list,   must = True)
        # class_data = args.parse(jdata)
        self.sel_a = sel_a
        self.sel_r = sel_r
        self.axis_rule = axis_rule
        self.rcut_r = rcut
        # ntypes and rcut_a === -1
        self.ntypes = len(self.sel_a)
        assert(self.ntypes == len(self.sel_r))
        self.rcut_a = -1
        # numb of neighbors and numb of descrptors
        self.nnei_a = np.cumsum(self.sel_a)[-1]
        self.nnei_r = np.cumsum(self.sel_r)[-1]
        self.nnei = self.nnei_a + self.nnei_r
        self.ndescrpt_a = self.nnei_a * 4
        self.ndescrpt_r = self.nnei_r * 1
        self.ndescrpt = self.ndescrpt_a + self.ndescrpt_r
        self.davg = None
        self.dstd = None

        self.place_holders = {}
        avg_zero = np.zeros([self.ntypes,self.ndescrpt]).astype(GLOBAL_NP_FLOAT_PRECISION)
        std_ones = np.ones ([self.ntypes,self.ndescrpt]).astype(GLOBAL_NP_FLOAT_PRECISION)
        sub_graph = tf.Graph()
        with sub_graph.as_default():
            name_pfx = 'd_lf_'
            for ii in ['coord', 'box']:
                self.place_holders[ii] = tf.placeholder(GLOBAL_NP_FLOAT_PRECISION, [None, None], name = name_pfx+'t_'+ii)
            self.place_holders['type'] = tf.placeholder(tf.int32, [None, None], name=name_pfx+'t_type')
            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, axis, rot_mat \
                = op_module.descrpt (self.place_holders['coord'],
                                     self.place_holders['type'],
                                     self.place_holders['natoms_vec'],
                                     self.place_holders['box'],
                                     self.place_holders['default_mesh'],
                                     tf.constant(avg_zero),
                                     tf.constant(std_ones),
                                     rcut_a = self.rcut_a,
                                     rcut_r = self.rcut_r,
                                     sel_a = self.sel_a,
                                     sel_r = self.sel_r,
                                     axis_rule = self.axis_rule)
        self.sub_sess = tf.Session(graph = sub_graph, config=default_tf_session_config)
Exemplo n.º 9
0
 def _get_place_horders(self, data_dict):
     for kk in data_dict.keys():
         if kk == 'type':
             continue
         prec = GLOBAL_TF_FLOAT_PRECISION
         if data_dict[kk]['high_prec'] :
             prec = GLOBAL_ENER_FLOAT_PRECISION
         self.place_holders[kk] = tf.placeholder(prec, [None], name = 't_' + kk)
         self.place_holders['find_' + kk] = tf.placeholder(tf.float32, name = 't_find_' + kk)
Exemplo n.º 10
0
 def setUp(self, data, sess=None):
     self.sess = sess
     self.data = data
     self.natoms = self.data.get_natoms()
     self.ntypes = self.data.get_ntypes()
     param_a = {
         'sel': [12, 24],
         'rcut': 4,
         'rcut_smth': 3.5,
         'neuron': [5, 10, 20],
         'seed': 1,
     }
     param_r = {
         'sel': [20, 40],
         'rcut': 6,
         'rcut_smth': 6.5,
         'neuron': [10, 20, 40],
         'seed': 1,
     }
     param = {'a': param_a, 'r': param_r}
     self.descrpt = DescrptSeAR(param)
     self.ndescrpt = self.descrpt.get_dim_out()
     # davg = np.zeros ([self.ntypes, self.ndescrpt])
     # dstd = np.ones  ([self.ntypes, self.ndescrpt])
     # self.t_avg = tf.constant(davg.astype(np.float64))
     # self.t_std = tf.constant(dstd.astype(np.float64))
     avg_a = np.zeros([self.ntypes, self.descrpt.descrpt_a.ndescrpt])
     std_a = np.ones([self.ntypes, self.descrpt.descrpt_a.ndescrpt])
     avg_r = np.zeros([self.ntypes, self.descrpt.descrpt_r.ndescrpt])
     std_r = np.ones([self.ntypes, self.descrpt.descrpt_r.ndescrpt])
     self.avg = [avg_a, avg_r]
     self.std = [std_a, std_r]
     self.default_mesh = np.zeros(6, dtype=np.int32)
     self.default_mesh[3] = 2
     self.default_mesh[4] = 2
     self.default_mesh[5] = 2
     # make place holder
     self.coord = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION,
                                 [None, self.natoms[0] * 3],
                                 name='t_coord')
     self.box = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None, 9],
                               name='t_box')
     self.type = tf.placeholder(tf.int32, [None, self.natoms[0]],
                                name="t_type")
     self.tnatoms = tf.placeholder(tf.int32, [None], name="t_natoms")
     self.efield = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION,
                                  [None, self.natoms[0] * 3],
                                  name='t_efield')
Exemplo n.º 11
0
 def __init__(self, hh, beta):
     self.hh = hh
     self.beta = beta
     with tf.Graph().as_default() as graph:
         # place holders
         self.t_nloc = tf.placeholder(tf.int32, [1], name="t_nloc")
         self.t_coord = tf.placeholder(global_tf_float_precision, [None],
                                       name='t_coord')
         self.t_charge = tf.placeholder(global_tf_float_precision, [None],
                                        name='t_charge')
         self.t_box = tf.placeholder(global_tf_float_precision, [None],
                                     name='t_box')
         # output
         self.t_energy, self.t_force, self.t_virial \
             = op_module.ewald_recp(self.t_coord, self.t_charge, self.t_nloc, self.t_box,
                                    ewald_h = self.hh,
                                    ewald_beta = self.beta)
     self.sess = tf.Session(graph=graph, config=default_tf_session_config)
Exemplo n.º 12
0
 def setUp(self):
     boxl = 4.5  # NOTICE grid should not change before and after box pert...
     box_pert = 0.2
     self.natoms = 16
     self.nframes = 2
     self.ewald_h = 1
     self.ewald_beta = 1
     self.dbox = []
     self.dcoord = []
     self.rcoord = []
     self.dcharge = []
     for ii in range(self.nframes):
         # box
         box = np.eye(3) * boxl
         box[1][1] += 1
         box[2][2] += 2
         box += np.random.random([3, 3]) * box_pert
         box = 0.5 * (box + box.T)
         self.dbox.append(box)
         # scaled
         coord = np.random.random([self.natoms, 3])
         self.rcoord.append(coord)
         # real coords
         self.dcoord.append(np.matmul(coord, box))
         # charge
         dcharge = np.random.random([self.natoms])
         dcharge -= np.average(dcharge)
         assert (np.abs(np.sum(self.dcharge) - 0) < 1e-12)
         self.dcharge.append(dcharge)
     self.dbox = np.array(self.dbox).reshape([self.nframes, 9])
     self.rcoord = np.array(self.rcoord).reshape(
         [self.nframes, 3 * self.natoms])
     self.dcoord = np.array(self.dcoord).reshape(
         [self.nframes, 3 * self.natoms])
     self.dcharge = np.array(self.dcharge).reshape(
         [self.nframes, self.natoms])
     # place holders
     self.coord = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None],
                                 name='t_coord')
     self.charge = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None],
                                  name='t_charge')
     self.box = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None],
                               name='t_box')
     self.nloc = tf.placeholder(tf.int32, [1], name="t_nloc")
Exemplo n.º 13
0
    def _build_network(self, data):        
        self.place_holders = {}
        data_dict = data.get_data_dict()
        for kk in data_dict.keys():
            if kk == 'type':
                continue
            prec = global_tf_float_precision
            if data_dict[kk]['high_prec'] :
                prec = global_ener_float_precision
            self.place_holders[kk] = tf.placeholder(prec, [None], name = 't_' + kk)
            self.place_holders['find_'+kk] = tf.placeholder(tf.float32, name = 't_find_' + kk)

        self.place_holders['type']      = tf.placeholder(tf.int32,   [None], name='t_type')
        self.place_holders['natoms_vec']        = tf.placeholder(tf.int32,   [self.ntypes+2], name='t_natoms')
        self.place_holders['default_mesh']      = tf.placeholder(tf.int32,   [None], name='t_mesh')
        self.place_holders['is_training']       = tf.placeholder(tf.bool)

        self.model_pred\
            = self.model.build (self.place_holders['coord'], 
                                self.place_holders['type'], 
                                self.place_holders['natoms_vec'], 
                                self.place_holders['box'], 
                                self.place_holders['default_mesh'],
                                self.place_holders,
                                suffix = "", 
                                reuse = False)

        self.l2_l, self.l2_more\
            = self.loss.build (self.learning_rate,
                               self.place_holders['natoms_vec'], 
                               self.model_pred,
                               self.place_holders,
                               suffix = "test")

        self._message("built network")
Exemplo n.º 14
0
    def _build_fv_graph_inner(self):
        self.t_ef = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None],
                                   name='t_ef')
        nf = 10
        nfxnas = 64 * nf
        nfxna = 192 * nf
        nf = -1
        nfxnas = -1
        nfxna = -1
        self.t_box_reshape = tf.reshape(self.t_box, [-1, 9])
        t_nframes = tf.shape(self.t_box_reshape)[0]
        # (nframes x natoms_sel) x 1 x 3
        self.t_ef_reshape = tf.reshape(self.t_ef, [nfxnas, 1, 3])
        # (nframes x natoms) x ndescrpt
        self.descrpt = self.graph.get_tensor_by_name(
            os.path.join(self.modifier_prefix, 'o_rmat:0'))
        self.descrpt_deriv = self.graph.get_tensor_by_name(
            os.path.join(self.modifier_prefix, 'o_rmat_deriv:0'))
        self.nlist = self.graph.get_tensor_by_name(
            os.path.join(self.modifier_prefix, 'o_nlist:0'))
        self.rij = self.graph.get_tensor_by_name(
            os.path.join(self.modifier_prefix, 'o_rij:0'))
        # self.descrpt_reshape = tf.reshape(self.descrpt, [nf, 192 * self.ndescrpt])
        # self.descrpt_deriv = tf.reshape(self.descrpt_deriv, [nf, 192 * self.ndescrpt * 3])

        # nframes x (natoms_sel x 3)
        self.t_tensor_reshpe = tf.reshape(self.t_tensor, [t_nframes, -1])
        # nframes x (natoms x 3)
        self.t_tensor_reshpe = self._enrich(self.t_tensor_reshpe, dof=3)
        # (nframes x natoms) x 3
        self.t_tensor_reshpe = tf.reshape(self.t_tensor_reshpe, [nfxna, 3])
        # (nframes x natoms) x 1
        self.t_dipole_x = tf.slice(self.t_tensor_reshpe, [0, 0], [nfxna, 1])
        self.t_dipole_y = tf.slice(self.t_tensor_reshpe, [0, 1], [nfxna, 1])
        self.t_dipole_z = tf.slice(self.t_tensor_reshpe, [0, 2], [nfxna, 1])
        self.t_dipole_z = tf.reshape(self.t_dipole_z, [nfxna, 1])
        # (nframes x natoms) x ndescrpt
        [self.t_dipole_x_d] = tf.gradients(self.t_dipole_x, self.descrpt)
        [self.t_dipole_y_d] = tf.gradients(self.t_dipole_y, self.descrpt)
        [self.t_dipole_z_d] = tf.gradients(self.t_dipole_z, self.descrpt)
        # nframes x (natoms x ndescrpt)
        self.t_dipole_x_d = tf.reshape(self.t_dipole_x_d,
                                       [-1, self.t_natoms[0] * self.ndescrpt])
        self.t_dipole_y_d = tf.reshape(self.t_dipole_y_d,
                                       [-1, self.t_natoms[0] * self.ndescrpt])
        self.t_dipole_z_d = tf.reshape(self.t_dipole_z_d,
                                       [-1, self.t_natoms[0] * self.ndescrpt])
        # nframes x (natoms_sel x ndescrpt)
        self.t_dipole_x_d = self._slice_descrpt_deriv(self.t_dipole_x_d)
        self.t_dipole_y_d = self._slice_descrpt_deriv(self.t_dipole_y_d)
        self.t_dipole_z_d = self._slice_descrpt_deriv(self.t_dipole_z_d)
        # (nframes x natoms_sel) x ndescrpt
        self.t_dipole_x_d = tf.reshape(self.t_dipole_x_d,
                                       [nfxnas, self.ndescrpt])
        self.t_dipole_y_d = tf.reshape(self.t_dipole_y_d,
                                       [nfxnas, self.ndescrpt])
        self.t_dipole_z_d = tf.reshape(self.t_dipole_z_d,
                                       [nfxnas, self.ndescrpt])
        # (nframes x natoms_sel) x 3 x ndescrpt
        self.t_dipole_d = tf.concat(
            [self.t_dipole_x_d, self.t_dipole_y_d, self.t_dipole_z_d], axis=1)
        self.t_dipole_d = tf.reshape(self.t_dipole_d,
                                     [nfxnas, 3 * self.ndescrpt])
        # (nframes x natoms_sel) x 3 x ndescrpt
        self.t_dipole_d = tf.reshape(self.t_dipole_d, [-1, 3, self.ndescrpt])
        # (nframes x natoms_sel) x 1 x ndescrpt
        self.t_ef_d = tf.matmul(self.t_ef_reshape, self.t_dipole_d)
        # nframes x (natoms_sel x ndescrpt)
        self.t_ef_d = tf.reshape(self.t_ef_d, [t_nframes, -1])
        # nframes x (natoms x ndescrpt)
        self.t_ef_d = self._enrich(self.t_ef_d, dof=self.ndescrpt)
        self.t_ef_d = tf.reshape(self.t_ef_d,
                                 [nf, self.t_natoms[0] * self.ndescrpt])
        # t_ef_d is force (with -1), prod_forc takes deriv, so we need the opposite
        self.t_ef_d_oppo = -self.t_ef_d

        force = op_module.prod_force_se_a(self.t_ef_d_oppo,
                                          self.descrpt_deriv,
                                          self.nlist,
                                          self.t_natoms,
                                          n_a_sel=self.nnei_a,
                                          n_r_sel=self.nnei_r)
        virial, atom_virial \
            = op_module.prod_virial_se_a (self.t_ef_d_oppo,
                                          self.descrpt_deriv,
                                          self.rij,
                                          self.nlist,
                                          self.t_natoms,
                                          n_a_sel = self.nnei_a,
                                          n_r_sel = self.nnei_r)
        force = tf.identity(force, name='o_dm_force')
        virial = tf.identity(virial, name='o_dm_virial')
        atom_virial = tf.identity(atom_virial, name='o_dm_av')
        return force, virial, atom_virial
Exemplo n.º 15
0
    def test_model(self):
        jfile = 'water_se_a_type.json'
        jdata = j_loader(jfile)

        systems = j_must_have(jdata, 'systems')
        set_pfx = j_must_have(jdata, 'set_prefix')
        batch_size = j_must_have(jdata, 'batch_size')
        test_size = j_must_have(jdata, 'numb_test')
        batch_size = 1
        test_size = 1
        stop_batch = j_must_have(jdata, 'stop_batch')
        rcut = j_must_have (jdata['model']['descriptor'], 'rcut')
        
        data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt = None)
        
        test_data = data.get_test ()
        numb_test = 1

        jdata['model']['descriptor'].pop('type', None)        
        descrpt = DescrptSeA(**jdata['model']['descriptor'], uniform_seed = True)
        jdata['model']['fitting_net']['descrpt'] = descrpt
        fitting = EnerFitting(**jdata['model']['fitting_net'], uniform_seed = True)
        typeebd_param = jdata['model']['type_embedding']
        typeebd = TypeEmbedNet(
            neuron = typeebd_param['neuron'],
            resnet_dt = typeebd_param['resnet_dt'],
            seed = typeebd_param['seed'], 
            uniform_seed = True)
        model = EnerModel(descrpt, fitting, typeebd)

        # model._compute_dstats([test_data['coord']], [test_data['box']], [test_data['type']], [test_data['natoms_vec']], [test_data['default_mesh']])
        input_data = {'coord' : [test_data['coord']], 
                      'box': [test_data['box']], 
                      'type': [test_data['type']],
                      'natoms_vec' : [test_data['natoms_vec']],
                      'default_mesh' : [test_data['default_mesh']]
        }
        model._compute_input_stat(input_data)
        model.descrpt.bias_atom_e = data.compute_energy_shift()

        t_prop_c           = tf.placeholder(tf.float32, [5],    name='t_prop_c')
        t_energy           = tf.placeholder(GLOBAL_ENER_FLOAT_PRECISION, [None], name='t_energy')
        t_force            = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None], name='t_force')
        t_virial           = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None], name='t_virial')
        t_atom_ener        = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None], name='t_atom_ener')
        t_coord            = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None], name='i_coord')
        t_type             = tf.placeholder(tf.int32,   [None], name='i_type')
        t_natoms           = tf.placeholder(tf.int32,   [model.ntypes+2], name='i_natoms')
        t_box              = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None, 9], name='i_box')
        t_mesh             = tf.placeholder(tf.int32,   [None], name='i_mesh')
        is_training        = tf.placeholder(tf.bool)
        t_fparam = None
        inputs_dict = {}

        model_pred \
            = model.build (t_coord, 
                           t_type, 
                           t_natoms, 
                           t_box, 
                           t_mesh,
                           inputs_dict,
                           suffix = "se_a_type", 
                           reuse = False)
        energy = model_pred['energy']
        force  = model_pred['force']
        virial = model_pred['virial']
        atom_ener =  model_pred['atom_ener']

        feed_dict_test = {t_prop_c:        test_data['prop_c'],
                          t_energy:        test_data['energy']              [:numb_test],
                          t_force:         np.reshape(test_data['force']    [:numb_test, :], [-1]),
                          t_virial:        np.reshape(test_data['virial']   [:numb_test, :], [-1]),
                          t_atom_ener:     np.reshape(test_data['atom_ener'][:numb_test, :], [-1]),
                          t_coord:         np.reshape(test_data['coord']    [:numb_test, :], [-1]),
                          t_box:           test_data['box']                 [:numb_test, :],
                          t_type:          np.reshape(test_data['type']     [:numb_test, :], [-1]),
                          t_natoms:        test_data['natoms_vec'],
                          t_mesh:          test_data['default_mesh'],
                          is_training:     False}

        sess = self.test_session().__enter__()
        sess.run(tf.global_variables_initializer())
        [e, f, v] = sess.run([energy, force, virial], 
                             feed_dict = feed_dict_test)
        # print(sess.run(model.type_embedding))
        # np.savetxt('tmp.out', sess.run(descrpt.dout, feed_dict = feed_dict_test), fmt='%.10e')
        # # print(sess.run(model.atype_embed, feed_dict = feed_dict_test))
        # print(sess.run(fitting.inputs, feed_dict = feed_dict_test))
        # print(sess.run(fitting.outs, feed_dict = feed_dict_test))
        # print(sess.run(fitting.atype_embed, feed_dict = feed_dict_test))

        e = e.reshape([-1])
        f = f.reshape([-1])
        v = v.reshape([-1])
        np.savetxt('e.out', e.reshape([1, -1]), delimiter=',')
        np.savetxt('f.out', f.reshape([1, -1]), delimiter=',')
        np.savetxt('v.out', v.reshape([1, -1]), delimiter=',')

        refe = [6.049065170680415804e+01]
        reff = [1.021832439441947293e-01,1.122650466359011306e-01,3.927874278714531091e-03,1.407089812207832635e-01,1.312473824343091400e-01,-1.228371057389851181e-02,-1.109672154547165501e-01,6.582735820731049070e-02,1.251568633647655391e-03,7.933758749748777428e-02,-1.831777072317984367e-01,-6.173090134630876760e-03,-2.703597126460742794e-01,4.817856571062521104e-02,1.491963457594796399e-02,5.909711543832503466e-02,-1.743406457563475287e-01,-1.642276779780762769e-03]
        refv = [-6.932736357193732823e-01,1.453756052949563837e-01,2.138263139115256783e-02,1.453756052949564392e-01,-3.880901656480436612e-01,-7.782259726407755700e-03,2.138263139115256437e-02,-7.782259726407749628e-03,-1.225285973678705374e-03]

        refe = np.reshape(refe, [-1])
        reff = np.reshape(reff, [-1])
        refv = np.reshape(refv, [-1])

        places = 10
        np.testing.assert_almost_equal(e, refe, places)
        np.testing.assert_almost_equal(f, reff, places)
        np.testing.assert_almost_equal(v, refv, places)
Exemplo n.º 16
0
    def test_model(self):
        jfile = 'water_se_r.json'
        with open(jfile) as fp:
            jdata = json.load (fp)
        run_opt = RunOptions(None) 
        systems = j_must_have(jdata, 'systems')
        set_pfx = j_must_have(jdata, 'set_prefix')
        batch_size = j_must_have(jdata, 'batch_size')
        test_size = j_must_have(jdata, 'numb_test')
        batch_size = 1
        test_size = 1
        stop_batch = j_must_have(jdata, 'stop_batch')
        rcut = j_must_have (jdata['model']['descriptor'], 'rcut')
        
        data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt = None)
        
        test_data = data.get_test ()
        numb_test = 1
        
        descrpt = DescrptSeR(jdata['model']['descriptor'])
        fitting = EnerFitting(jdata['model']['fitting_net'], descrpt)
        model = Model(jdata['model'], descrpt, fitting)

        # model._compute_dstats([test_data['coord']], [test_data['box']], [test_data['type']], [test_data['natoms_vec']], [test_data['default_mesh']])
        input_data = {'coord' : [test_data['coord']], 
                      'box': [test_data['box']], 
                      'type': [test_data['type']],
                      'natoms_vec' : [test_data['natoms_vec']],
                      'default_mesh' : [test_data['default_mesh']]
        }
        model._compute_input_stat(input_data)
        model.descrpt.bias_atom_e = data.compute_energy_shift()

        t_prop_c           = tf.placeholder(tf.float32, [5],    name='t_prop_c')
        t_energy           = tf.placeholder(global_ener_float_precision, [None], name='t_energy')
        t_force            = tf.placeholder(global_tf_float_precision, [None], name='t_force')
        t_virial           = tf.placeholder(global_tf_float_precision, [None], name='t_virial')
        t_atom_ener        = tf.placeholder(global_tf_float_precision, [None], name='t_atom_ener')
        t_coord            = tf.placeholder(global_tf_float_precision, [None], name='i_coord')
        t_type             = tf.placeholder(tf.int32,   [None], name='i_type')
        t_natoms           = tf.placeholder(tf.int32,   [model.ntypes+2], name='i_natoms')
        t_box              = tf.placeholder(global_tf_float_precision, [None, 9], name='i_box')
        t_mesh             = tf.placeholder(tf.int32,   [None], name='i_mesh')
        is_training        = tf.placeholder(tf.bool)
        t_fparam = None

        model_pred\
            = model.build (t_coord, 
                           t_type, 
                           t_natoms, 
                           t_box, 
                           t_mesh,
                           t_fparam,
                           suffix = "se_r", 
                           reuse = False)
        energy = model_pred['energy']
        force  = model_pred['force']
        virial = model_pred['virial']
        atom_ener =  model_pred['atom_ener']

        feed_dict_test = {t_prop_c:        test_data['prop_c'],
                          t_energy:        test_data['energy']              [:numb_test],
                          t_force:         np.reshape(test_data['force']    [:numb_test, :], [-1]),
                          t_virial:        np.reshape(test_data['virial']   [:numb_test, :], [-1]),
                          t_atom_ener:     np.reshape(test_data['atom_ener'][:numb_test, :], [-1]),
                          t_coord:         np.reshape(test_data['coord']    [:numb_test, :], [-1]),
                          t_box:           test_data['box']                 [:numb_test, :],
                          t_type:          np.reshape(test_data['type']     [:numb_test, :], [-1]),
                          t_natoms:        test_data['natoms_vec'],
                          t_mesh:          test_data['default_mesh'],
                          is_training:     False}

        sess = tf.Session()
        sess.run(tf.global_variables_initializer())
        [e, f, v] = sess.run([energy, force, virial], 
                             feed_dict = feed_dict_test)

        e = e.reshape([-1])
        f = f.reshape([-1])
        v = v.reshape([-1])
        refe = [6.152085988309423925e+01]
        reff = [-1.714443151616400110e-04,-1.315836609370952051e-04,-5.584120460897444674e-06,-7.197863450669731334e-05,-1.384609799994930676e-04,8.856091902774708468e-06,1.120578238869146797e-04,-7.428703645877488470e-05,9.370560731488587317e-07,-1.048347129617610465e-04,1.977876923815685781e-04,7.522050342771599598e-06,2.361772659657814205e-04,-5.774651813388292487e-05,-1.233143271630744828e-05,2.257277740226381951e-08,2.042905031476775584e-04,6.003548585097267914e-07]
        refv = [1.035180911513190792e-03,-1.118982949050497126e-04,-2.383287813436022850e-05,-1.118982949050497126e-04,4.362023915782403281e-04,8.119543218224559240e-06,-2.383287813436022850e-05,8.119543218224559240e-06,1.201142938802945237e-06]
        refe = np.reshape(refe, [-1])
        reff = np.reshape(reff, [-1])
        refv = np.reshape(refv, [-1])

        places = 6
        for ii in range(e.size) :
            self.assertAlmostEqual(e[ii], refe[ii], places = places)
        for ii in range(f.size) :
            self.assertAlmostEqual(f[ii], reff[ii], places = places)
        for ii in range(v.size) :
            self.assertAlmostEqual(v[ii], refv[ii], places = places)
Exemplo n.º 17
0
    def __init__(self,
                 rcut: float,
                 rcut_smth: float,
                 sel: List[str],
                 neuron: List[int] = [24, 48, 96],
                 resnet_dt: bool = False,
                 trainable: bool = True,
                 seed: int = None,
                 set_davg_zero: bool = False,
                 activation_function: str = 'tanh',
                 precision: str = 'default',
                 uniform_seed: bool = False) -> None:
        """
        Constructor
        """
        self.sel_a = sel
        self.rcut_r = rcut
        self.rcut_r_smth = rcut_smth
        self.filter_neuron = neuron
        self.filter_resnet_dt = resnet_dt
        self.seed = seed
        self.uniform_seed = uniform_seed
        self.seed_shift = embedding_net_rand_seed_shift(self.filter_neuron)
        self.trainable = trainable
        self.filter_activation_fn = get_activation_func(activation_function)
        self.filter_precision = get_precision(precision)
        # self.exclude_types = set()
        # for tt in exclude_types:
        #     assert(len(tt) == 2)
        #     self.exclude_types.add((tt[0], tt[1]))
        #     self.exclude_types.add((tt[1], tt[0]))
        self.set_davg_zero = set_davg_zero

        # descrpt config
        self.sel_r = [0 for ii in range(len(self.sel_a))]
        self.ntypes = len(self.sel_a)
        assert (self.ntypes == len(self.sel_r))
        self.rcut_a = -1
        # numb of neighbors and numb of descrptors
        self.nnei_a = np.cumsum(self.sel_a)[-1]
        self.nnei_r = np.cumsum(self.sel_r)[-1]
        self.nnei = self.nnei_a + self.nnei_r
        self.ndescrpt_a = self.nnei_a * 4
        self.ndescrpt_r = self.nnei_r * 1
        self.ndescrpt = self.ndescrpt_a + self.ndescrpt_r
        self.useBN = False
        self.dstd = None
        self.davg = None

        self.place_holders = {}
        avg_zero = np.zeros([self.ntypes,
                             self.ndescrpt]).astype(GLOBAL_NP_FLOAT_PRECISION)
        std_ones = np.ones([self.ntypes,
                            self.ndescrpt]).astype(GLOBAL_NP_FLOAT_PRECISION)
        sub_graph = tf.Graph()
        with sub_graph.as_default():
            name_pfx = 'd_sea_'
            for ii in ['coord', 'box']:
                self.place_holders[ii] = tf.placeholder(
                    GLOBAL_NP_FLOAT_PRECISION, [None, None],
                    name=name_pfx + 't_' + ii)
            self.place_holders['type'] = tf.placeholder(tf.int32, [None, None],
                                                        name=name_pfx +
                                                        't_type')
            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.prod_env_mat_a(self.place_holders['coord'],
                                         self.place_holders['type'],
                                         self.place_holders['natoms_vec'],
                                         self.place_holders['box'],
                                         self.place_holders['default_mesh'],
                                         tf.constant(avg_zero),
                                         tf.constant(std_ones),
                                         rcut_a = self.rcut_a,
                                         rcut_r = self.rcut_r,
                                         rcut_r_smth = self.rcut_r_smth,
                                         sel_a = self.sel_a,
                                         sel_r = self.sel_r)
        self.sub_sess = tf.Session(graph=sub_graph,
                                   config=default_tf_session_config)
    def test_model(self):
        jfile = 'water_se_a_aparam.json'
        with open(jfile) as fp:
            jdata = json.load(fp)
        run_opt = RunOptions(None)
        systems = j_must_have(jdata, 'systems')
        set_pfx = j_must_have(jdata, 'set_prefix')
        batch_size = j_must_have(jdata, 'batch_size')
        test_size = j_must_have(jdata, 'numb_test')
        batch_size = 1
        test_size = 1
        stop_batch = j_must_have(jdata, 'stop_batch')
        rcut = j_must_have(jdata['model']['descriptor'], 'rcut')

        data = DataSystem(systems,
                          set_pfx,
                          batch_size,
                          test_size,
                          rcut,
                          run_opt=None)

        test_data = data.get_test()
        # manually set aparam
        test_data['aparam'] = np.load('system/set.000/aparam.npy')
        numb_test = 1

        descrpt = DescrptSeA(jdata['model']['descriptor'])
        fitting = EnerFitting(jdata['model']['fitting_net'], descrpt)
        model = Model(jdata['model'], descrpt, fitting)

        # model._compute_dstats([test_data['coord']], [test_data['box']], [test_data['type']], [test_data['natoms_vec']], [test_data['default_mesh']])
        input_data = {
            'coord': [test_data['coord']],
            'box': [test_data['box']],
            'type': [test_data['type']],
            'natoms_vec': [test_data['natoms_vec']],
            'default_mesh': [test_data['default_mesh']],
            'aparam': [test_data['aparam']],
        }
        model._compute_dstats(input_data)
        model.bias_atom_e = data.compute_energy_shift()

        t_prop_c = tf.placeholder(tf.float32, [5], name='t_prop_c')
        t_energy = tf.placeholder(global_ener_float_precision, [None],
                                  name='t_energy')
        t_force = tf.placeholder(global_tf_float_precision, [None],
                                 name='t_force')
        t_virial = tf.placeholder(global_tf_float_precision, [None],
                                  name='t_virial')
        t_atom_ener = tf.placeholder(global_tf_float_precision, [None],
                                     name='t_atom_ener')
        t_coord = tf.placeholder(global_tf_float_precision, [None],
                                 name='i_coord')
        t_type = tf.placeholder(tf.int32, [None], name='i_type')
        t_natoms = tf.placeholder(tf.int32, [model.ntypes + 2],
                                  name='i_natoms')
        t_box = tf.placeholder(global_tf_float_precision, [None, 9],
                               name='i_box')
        t_mesh = tf.placeholder(tf.int32, [None], name='i_mesh')
        t_aparam = tf.placeholder(global_tf_float_precision, [None],
                                  name='i_aparam')
        is_training = tf.placeholder(tf.bool)
        input_dict = {}
        input_dict['aparam'] = t_aparam

        model_pred\
            = model.build (t_coord,
                           t_type,
                           t_natoms,
                           t_box,
                           t_mesh,
                           input_dict,
                           suffix = "se_a_aparam",
                           reuse = False)
        energy = model_pred['energy']
        force = model_pred['force']
        virial = model_pred['virial']
        atom_ener = model_pred['atom_ener']

        feed_dict_test = {
            t_prop_c: test_data['prop_c'],
            t_energy: test_data['energy'][:numb_test],
            t_force: np.reshape(test_data['force'][:numb_test, :], [-1]),
            t_virial: np.reshape(test_data['virial'][:numb_test, :], [-1]),
            t_atom_ener: np.reshape(test_data['atom_ener'][:numb_test, :],
                                    [-1]),
            t_coord: np.reshape(test_data['coord'][:numb_test, :], [-1]),
            t_box: test_data['box'][:numb_test, :],
            t_type: np.reshape(test_data['type'][:numb_test, :], [-1]),
            t_natoms: test_data['natoms_vec'],
            t_mesh: test_data['default_mesh'],
            t_aparam: np.reshape(test_data['aparam'][:numb_test, :], [-1]),
            is_training: False
        }

        sess = tf.Session()
        sess.run(tf.global_variables_initializer())
        [e, f, v] = sess.run([energy, force, virial], feed_dict=feed_dict_test)

        e = e.reshape([-1])
        f = f.reshape([-1])
        v = v.reshape([-1])
        refe = [61.35473702079649]
        reff = [
            7.789591210641927388e-02, 9.411176646369459609e-02,
            3.785806413688173194e-03, 1.430830954178063386e-01,
            1.146964190520970150e-01, -1.320340288927138173e-02,
            -7.308720494747594776e-02, 6.508269338140809657e-02,
            5.398739145542804643e-04, 5.863268336973800898e-02,
            -1.603409523950408699e-01, -5.083084610994957619e-03,
            -2.551569799443983988e-01, 3.087934885732580501e-02,
            1.508590526622844222e-02, 4.863249399791078065e-02,
            -1.444292753594846324e-01, -1.125098094204559241e-03
        ]
        refv = [
            -6.069498397488943819e-01, 1.101778888191114192e-01,
            1.981907430646132409e-02, 1.101778888191114608e-01,
            -3.315612988100872793e-01, -5.999739184898976799e-03,
            1.981907430646132756e-02, -5.999739184898974197e-03,
            -1.198656608172396325e-03
        ]
        refe = np.reshape(refe, [-1])
        reff = np.reshape(reff, [-1])
        refv = np.reshape(refv, [-1])

        places = 10
        for ii in range(e.size):
            self.assertAlmostEqual(e[ii], refe[ii], places=places)
        for ii in range(f.size):
            self.assertAlmostEqual(f[ii], reff[ii], places=places)
        for ii in range(v.size):
            self.assertAlmostEqual(v[ii], refv[ii], places=places)
Exemplo n.º 19
0
    def __init__(
        self,
        op,
        rcut: float,
        rcut_smth: float,
        sel: List[str],
        neuron: List[int] = [24, 48, 96],
        axis_neuron: int = 8,
        resnet_dt: bool = False,
        trainable: bool = True,
        seed: int = None,
        type_one_side: bool = True,
        exclude_types: List[List[int]] = [],
        set_davg_zero: bool = False,
        activation_function: str = 'tanh',
        precision: str = 'default',
        uniform_seed: bool = False,
    ) -> None:
        DescrptSeA.__init__(self, rcut, rcut_smth, sel, neuron, axis_neuron,
                            resnet_dt, trainable, seed, type_one_side,
                            exclude_types, set_davg_zero, activation_function,
                            precision, uniform_seed)
        # DescrptSeA.__init__(self, **jdata)
        # args = ClassArg()\
        #        .add('sel',      list,   must = True) \
        #        .add('rcut',     float,  default = 6.0) \
        #        .add('rcut_smth',float,  default = 5.5) \
        #        .add('neuron',   list,   default = [10, 20, 40]) \
        #        .add('axis_neuron', int, default = 4, alias = 'n_axis_neuron') \
        #        .add('resnet_dt',bool,   default = False) \
        #        .add('trainable',bool,   default = True) \
        #        .add('seed',     int)
        # class_data = args.parse(jdata)
        # self.sel_a = class_data['sel']
        # self.rcut_r = class_data['rcut']
        # self.rcut_r_smth = class_data['rcut_smth']
        # self.filter_neuron = class_data['neuron']
        # self.n_axis_neuron = class_data['axis_neuron']
        # self.filter_resnet_dt = class_data['resnet_dt']
        # self.seed = class_data['seed']
        # self.trainable = class_data['trainable']
        self.sel_a = sel
        self.rcut_r = rcut
        self.rcut_r_smth = rcut_smth
        self.filter_neuron = neuron
        self.n_axis_neuron = axis_neuron
        self.filter_resnet_dt = resnet_dt
        self.seed = seed
        self.trainable = trainable
        self.op = op

        # descrpt config
        self.sel_r = [0 for ii in range(len(self.sel_a))]
        self.ntypes = len(self.sel_a)
        assert (self.ntypes == len(self.sel_r))
        self.rcut_a = -1
        # numb of neighbors and numb of descrptors
        self.nnei_a = np.cumsum(self.sel_a)[-1]
        self.nnei_r = np.cumsum(self.sel_r)[-1]
        self.nnei = self.nnei_a + self.nnei_r
        self.ndescrpt_a = self.nnei_a * 4
        self.ndescrpt_r = self.nnei_r * 1
        self.ndescrpt = self.ndescrpt_a + self.ndescrpt_r
        self.useBN = False
        self.dstd = None
        self.davg = None

        add_data_requirement('efield',
                             3,
                             atomic=True,
                             must=True,
                             high_prec=False)

        self.place_holders = {}
        avg_zero = np.zeros([self.ntypes,
                             self.ndescrpt]).astype(GLOBAL_NP_FLOAT_PRECISION)
        std_ones = np.ones([self.ntypes,
                            self.ndescrpt]).astype(GLOBAL_NP_FLOAT_PRECISION)
        sub_graph = tf.Graph()
        with sub_graph.as_default():
            name_pfx = 'd_sea_ef_'
            for ii in ['coord', 'box']:
                self.place_holders[ii] = tf.placeholder(
                    GLOBAL_NP_FLOAT_PRECISION, [None, None],
                    name=name_pfx + 't_' + ii)
            self.place_holders['type'] = tf.placeholder(tf.int32, [None, None],
                                                        name=name_pfx +
                                                        't_type')
            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.place_holders['efield'] = tf.placeholder(
                GLOBAL_NP_FLOAT_PRECISION, [None, None],
                name=name_pfx + 't_efield')
            self.stat_descrpt, descrpt_deriv, rij, nlist \
                = self.op(self.place_holders['coord'],
                          self.place_holders['type'],
                          self.place_holders['natoms_vec'],
                          self.place_holders['box'],
                          self.place_holders['default_mesh'],
                          self.place_holders['efield'],
                          tf.constant(avg_zero),
                          tf.constant(std_ones),
                          rcut_a = self.rcut_a,
                          rcut_r = self.rcut_r,
                          rcut_r_smth = self.rcut_r_smth,
                          sel_a = self.sel_a,
                          sel_r = self.sel_r)
        self.sub_sess = tf.Session(graph=sub_graph,
                                   config=default_tf_session_config)
Exemplo n.º 20
0
    def test_model(self):
        jfile = 'water.json'
        with open(jfile) as fp:
            jdata = json.load(fp)
        run_opt = RunOptions(None)
        systems = j_must_have(jdata, 'systems')
        set_pfx = j_must_have(jdata, 'set_prefix')
        batch_size = j_must_have(jdata, 'batch_size')
        test_size = j_must_have(jdata, 'numb_test')
        batch_size = 1
        test_size = 1
        stop_batch = j_must_have(jdata, 'stop_batch')
        rcut = j_must_have(jdata['model']['descriptor'], 'rcut')

        data = DataSystem(systems,
                          set_pfx,
                          batch_size,
                          test_size,
                          rcut,
                          run_opt=None)

        test_data = data.get_test()
        numb_test = 1

        descrpt = DescrptLocFrame(jdata['model']['descriptor'])
        fitting = EnerFitting(jdata['model']['fitting_net'], descrpt)
        model = Model(jdata['model'], descrpt, fitting)

        # model._compute_dstats([test_data['coord']], [test_data['box']], [test_data['type']], [test_data['natoms_vec']], [test_data['default_mesh']])
        input_data = {
            'coord': [test_data['coord']],
            'box': [test_data['box']],
            'type': [test_data['type']],
            'natoms_vec': [test_data['natoms_vec']],
            'default_mesh': [test_data['default_mesh']]
        }
        model._compute_input_stat(input_data)
        model.fitting.bias_atom_e = data.compute_energy_shift()

        t_prop_c = tf.placeholder(tf.float32, [5], name='t_prop_c')
        t_energy = tf.placeholder(global_ener_float_precision, [None],
                                  name='t_energy')
        t_force = tf.placeholder(global_tf_float_precision, [None],
                                 name='t_force')
        t_virial = tf.placeholder(global_tf_float_precision, [None],
                                  name='t_virial')
        t_atom_ener = tf.placeholder(global_tf_float_precision, [None],
                                     name='t_atom_ener')
        t_coord = tf.placeholder(global_tf_float_precision, [None],
                                 name='i_coord')
        t_type = tf.placeholder(tf.int32, [None], name='i_type')
        t_natoms = tf.placeholder(tf.int32, [model.ntypes + 2],
                                  name='i_natoms')
        t_box = tf.placeholder(global_tf_float_precision, [None, 9],
                               name='i_box')
        t_mesh = tf.placeholder(tf.int32, [None], name='i_mesh')
        is_training = tf.placeholder(tf.bool)
        t_fparam = None

        model_pred \
            = model.build (t_coord,
                           t_type,
                           t_natoms,
                           t_box,
                           t_mesh,
                           t_fparam,
                           suffix = "loc_frame",
                           reuse = False)
        energy = model_pred['energy']
        force = model_pred['force']
        virial = model_pred['virial']
        atom_ener = model_pred['atom_ener']

        feed_dict_test = {
            t_prop_c: test_data['prop_c'],
            t_energy: test_data['energy'][:numb_test],
            t_force: np.reshape(test_data['force'][:numb_test, :], [-1]),
            t_virial: np.reshape(test_data['virial'][:numb_test, :], [-1]),
            t_atom_ener: np.reshape(test_data['atom_ener'][:numb_test, :],
                                    [-1]),
            t_coord: np.reshape(test_data['coord'][:numb_test, :], [-1]),
            t_box: test_data['box'][:numb_test, :],
            t_type: np.reshape(test_data['type'][:numb_test, :], [-1]),
            t_natoms: test_data['natoms_vec'],
            t_mesh: test_data['default_mesh'],
            is_training: False
        }

        sess = tf.Session()
        sess.run(tf.global_variables_initializer())
        [e, f, v] = sess.run([energy, force, virial], feed_dict=feed_dict_test)

        e = e.reshape([-1])
        f = f.reshape([-1])
        v = v.reshape([-1])
        refe = [1.165945032784766511e+01]
        reff = [
            2.356319331246305437e-01, 1.772322096063349284e-01,
            1.455439548950788684e-02, 1.968599426000810226e-01,
            2.648214484898352983e-01, 7.595232354012236564e-02,
            -2.121321856338151401e-01, -2.463886119018566037e-03,
            -2.075636300914874069e-02, -9.360310077571798101e-03,
            -1.751965198776750943e-01, -2.046405309983102827e-02,
            -1.990194093283037535e-01, -1.828347741191920298e-02,
            -6.916374506995154325e-02, -1.197997068502068031e-02,
            -2.461097746875573200e-01, 1.987744214930105627e-02
        ]
        refv = [
            -4.998509978510510265e-01, -1.966169437179327711e-02,
            1.136130543869883977e-02, -1.966169437179334650e-02,
            -4.575353297894450555e-01, -2.668666556859019493e-03,
            1.136130543869887100e-02, -2.668666556859039876e-03,
            2.455466940358383508e-03
        ]
        refe = np.reshape(refe, [-1])
        reff = np.reshape(reff, [-1])
        refv = np.reshape(refv, [-1])

        places = 10
        for ii in range(e.size):
            self.assertAlmostEqual(e[ii], refe[ii], places=places)
        for ii in range(f.size):
            self.assertAlmostEqual(f[ii], reff[ii], places=places)
        for ii in range(v.size):
            self.assertAlmostEqual(v[ii], refv[ii], places=places)
Exemplo n.º 21
0
    def test_model(self):
        jfile = 'water_se_a.json'
        with open(jfile) as fp:
            jdata = json.load(fp)
        run_opt = RunOptions(None)
        systems = j_must_have(jdata, 'systems')
        set_pfx = j_must_have(jdata, 'set_prefix')
        batch_size = j_must_have(jdata, 'batch_size')
        test_size = j_must_have(jdata, 'numb_test')
        batch_size = 1
        test_size = 1
        stop_batch = j_must_have(jdata, 'stop_batch')
        rcut = j_must_have(jdata['model']['descriptor'], 'rcut')

        data = DataSystem(systems,
                          set_pfx,
                          batch_size,
                          test_size,
                          rcut,
                          run_opt=None)

        test_data = data.get_test()
        numb_test = 1

        descrpt = DescrptSeA(jdata['model']['descriptor'])
        fitting = EnerFitting(jdata['model']['fitting_net'], descrpt)
        model = Model(jdata['model'], descrpt, fitting)

        # model._compute_dstats([test_data['coord']], [test_data['box']], [test_data['type']], [test_data['natoms_vec']], [test_data['default_mesh']])
        input_data = {
            'coord': [test_data['coord']],
            'box': [test_data['box']],
            'type': [test_data['type']],
            'natoms_vec': [test_data['natoms_vec']],
            'default_mesh': [test_data['default_mesh']]
        }
        model._compute_dstats(input_data)
        model.bias_atom_e = data.compute_energy_shift()

        t_prop_c = tf.placeholder(tf.float32, [5], name='t_prop_c')
        t_energy = tf.placeholder(global_ener_float_precision, [None],
                                  name='t_energy')
        t_force = tf.placeholder(global_tf_float_precision, [None],
                                 name='t_force')
        t_virial = tf.placeholder(global_tf_float_precision, [None],
                                  name='t_virial')
        t_atom_ener = tf.placeholder(global_tf_float_precision, [None],
                                     name='t_atom_ener')
        t_coord = tf.placeholder(global_tf_float_precision, [None],
                                 name='i_coord')
        t_type = tf.placeholder(tf.int32, [None], name='i_type')
        t_natoms = tf.placeholder(tf.int32, [model.ntypes + 2],
                                  name='i_natoms')
        t_box = tf.placeholder(global_tf_float_precision, [None, 9],
                               name='i_box')
        t_mesh = tf.placeholder(tf.int32, [None], name='i_mesh')
        is_training = tf.placeholder(tf.bool)
        t_fparam = None

        model_pred \
            = model.build (t_coord,
                           t_type,
                           t_natoms,
                           t_box,
                           t_mesh,
                           t_fparam,
                           suffix = "se_a",
                           reuse = False)
        energy = model_pred['energy']
        force = model_pred['force']
        virial = model_pred['virial']
        atom_ener = model_pred['atom_ener']

        feed_dict_test = {
            t_prop_c: test_data['prop_c'],
            t_energy: test_data['energy'][:numb_test],
            t_force: np.reshape(test_data['force'][:numb_test, :], [-1]),
            t_virial: np.reshape(test_data['virial'][:numb_test, :], [-1]),
            t_atom_ener: np.reshape(test_data['atom_ener'][:numb_test, :],
                                    [-1]),
            t_coord: np.reshape(test_data['coord'][:numb_test, :], [-1]),
            t_box: test_data['box'][:numb_test, :],
            t_type: np.reshape(test_data['type'][:numb_test, :], [-1]),
            t_natoms: test_data['natoms_vec'],
            t_mesh: test_data['default_mesh'],
            is_training: False
        }

        sess = tf.Session()
        sess.run(tf.global_variables_initializer())
        [e, f, v] = sess.run([energy, force, virial], feed_dict=feed_dict_test)

        e = e.reshape([-1])
        f = f.reshape([-1])
        v = v.reshape([-1])
        refe = [6.135449167779321300e+01]
        reff = [
            7.799691562262310585e-02, 9.423098804815030483e-02,
            3.790560997388224204e-03, 1.432522403799846578e-01,
            1.148392791403983204e-01, -1.321871172563671148e-02,
            -7.318966526325138000e-02, 6.516069212737778116e-02,
            5.406418483320515412e-04, 5.870713761026503247e-02,
            -1.605402669549013672e-01, -5.089516979826595386e-03,
            -2.554593467731766654e-01, 3.092063507347833987e-02,
            1.510355029451411479e-02, 4.869271842355533952e-02,
            -1.446113274345035005e-01, -1.126524434771078789e-03
        ]
        refv = [
            -6.076776685178300053e-01, 1.103174323630009418e-01,
            1.984250991380156690e-02, 1.103174323630009557e-01,
            -3.319759402259439551e-01, -6.007404107650986258e-03,
            1.984250991380157036e-02, -6.007404107650981921e-03,
            -1.200076017439753642e-03
        ]
        refe = np.reshape(refe, [-1])
        reff = np.reshape(reff, [-1])
        refv = np.reshape(refv, [-1])

        places = 10
        for ii in range(e.size):
            self.assertAlmostEqual(e[ii], refe[ii], places=places)
        for ii in range(f.size):
            self.assertAlmostEqual(f[ii], reff[ii], places=places)
        for ii in range(v.size):
            self.assertAlmostEqual(v[ii], refv[ii], places=places)
Exemplo n.º 22
0
    def test_model(self):
        jfile = 'polar_se_a.json'
        with open(jfile) as fp:
            jdata = json.load(fp)
        run_opt = RunOptions(None)
        systems = j_must_have(jdata, 'systems')
        set_pfx = j_must_have(jdata, 'set_prefix')
        batch_size = j_must_have(jdata, 'batch_size')
        test_size = j_must_have(jdata, 'numb_test')
        batch_size = 1
        test_size = 1
        stop_batch = j_must_have(jdata, 'stop_batch')
        rcut = j_must_have(jdata['model']['descriptor'], 'rcut')

        data = DataSystem(systems,
                          set_pfx,
                          batch_size,
                          test_size,
                          rcut,
                          run_opt=None)

        test_data = data.get_test()
        numb_test = 1

        descrpt = DescrptSeA(jdata['model']['descriptor'])
        fitting = PolarFittingSeA(jdata['model']['fitting_net'], descrpt)
        model = PolarModel(jdata['model'], descrpt, fitting)

        model._compute_dstats([test_data['coord']], [test_data['box']],
                              [test_data['type']], [test_data['natoms_vec']],
                              [test_data['default_mesh']])

        t_prop_c = tf.placeholder(tf.float32, [5], name='t_prop_c')
        t_energy = tf.placeholder(global_ener_float_precision, [None],
                                  name='t_energy')
        t_force = tf.placeholder(global_tf_float_precision, [None],
                                 name='t_force')
        t_virial = tf.placeholder(global_tf_float_precision, [None],
                                  name='t_virial')
        t_atom_ener = tf.placeholder(global_tf_float_precision, [None],
                                     name='t_atom_ener')
        t_coord = tf.placeholder(global_tf_float_precision, [None],
                                 name='i_coord')
        t_type = tf.placeholder(tf.int32, [None], name='i_type')
        t_natoms = tf.placeholder(tf.int32, [model.ntypes + 2],
                                  name='i_natoms')
        t_box = tf.placeholder(global_tf_float_precision, [None, 9],
                               name='i_box')
        t_mesh = tf.placeholder(tf.int32, [None], name='i_mesh')
        is_training = tf.placeholder(tf.bool)
        t_fparam = None

        model_pred \
            = model.build (t_coord,
                           t_type,
                           t_natoms,
                           t_box,
                           t_mesh,
                           t_fparam,
                           suffix = "polar_se_a",
                           reuse = False)
        polar = model_pred['polar']

        feed_dict_test = {
            t_prop_c: test_data['prop_c'],
            t_coord: np.reshape(test_data['coord'][:numb_test, :], [-1]),
            t_box: test_data['box'][:numb_test, :],
            t_type: np.reshape(test_data['type'][:numb_test, :], [-1]),
            t_natoms: test_data['natoms_vec'],
            t_mesh: test_data['default_mesh'],
            is_training: False
        }

        sess = tf.Session()
        sess.run(tf.global_variables_initializer())
        [p] = sess.run([polar], feed_dict=feed_dict_test)

        p = p.reshape([-1])
        refp = [
            3.39695248e+01, 2.16564043e+01, 8.18501479e-01, 2.16564043e+01,
            1.38211789e+01, 5.22775159e-01, 8.18501479e-01, 5.22775159e-01,
            1.97847218e-02, 8.08467431e-01, 3.42081126e+00, -2.01072261e-01,
            3.42081126e+00, 1.54924596e+01, -9.06153697e-01, -2.01072261e-01,
            -9.06153697e-01, 5.30193262e-02
        ]

        places = 6
        for ii in range(p.size):
            self.assertAlmostEqual(p[ii], refp[ii], places=places)
Exemplo n.º 23
0
    def __init__(self,
                 rcut: float,
                 rcut_smth: float,
                 sel: List[str],
                 neuron: List[int] = [24, 48, 96],
                 resnet_dt: bool = False,
                 trainable: bool = True,
                 seed: int = None,
                 type_one_side: bool = True,
                 exclude_types: List[List[int]] = [],
                 set_davg_zero: bool = False,
                 activation_function: str = 'tanh',
                 precision: str = 'default',
                 uniform_seed: bool = False) -> None:
        """
        Constructor
        """
        # args = ClassArg()\
        #        .add('sel',      list,   must = True) \
        #        .add('rcut',     float,  default = 6.0) \
        #        .add('rcut_smth',float,  default = 0.5) \
        #        .add('neuron',   list,   default = [10, 20, 40]) \
        #        .add('resnet_dt',bool,   default = False) \
        #        .add('trainable',bool,   default = True) \
        #        .add('seed',     int) \
        #        .add('type_one_side', bool, default = False) \
        #        .add('exclude_types', list, default = []) \
        #        .add('set_davg_zero', bool, default = False) \
        #        .add("activation_function", str, default = "tanh") \
        #        .add("precision",           str, default = "default")
        # class_data = args.parse(jdata)
        self.sel_r = sel
        self.rcut = rcut
        self.rcut_smth = rcut_smth
        self.filter_neuron = neuron
        self.filter_resnet_dt = resnet_dt
        self.seed = seed
        self.uniform_seed = uniform_seed
        self.seed_shift = embedding_net_rand_seed_shift(self.filter_neuron)
        self.trainable = trainable
        self.filter_activation_fn = get_activation_func(activation_function)
        self.filter_precision = get_precision(precision)
        exclude_types = exclude_types
        self.exclude_types = set()
        for tt in exclude_types:
            assert (len(tt) == 2)
            self.exclude_types.add((tt[0], tt[1]))
            self.exclude_types.add((tt[1], tt[0]))
        self.set_davg_zero = set_davg_zero
        self.type_one_side = type_one_side

        # descrpt config
        self.sel_a = [0 for ii in range(len(self.sel_r))]
        self.ntypes = len(self.sel_r)
        # numb of neighbors and numb of descrptors
        self.nnei_a = np.cumsum(self.sel_a)[-1]
        self.nnei_r = np.cumsum(self.sel_r)[-1]
        self.nnei = self.nnei_a + self.nnei_r
        self.ndescrpt_a = self.nnei_a * 4
        self.ndescrpt_r = self.nnei_r * 1
        self.ndescrpt = self.nnei_r
        self.useBN = False
        self.davg = None
        self.dstd = None
        self.embedding_net_variables = None

        self.place_holders = {}
        avg_zero = np.zeros([self.ntypes,
                             self.ndescrpt]).astype(GLOBAL_NP_FLOAT_PRECISION)
        std_ones = np.ones([self.ntypes,
                            self.ndescrpt]).astype(GLOBAL_NP_FLOAT_PRECISION)
        sub_graph = tf.Graph()
        with sub_graph.as_default():
            name_pfx = 'd_ser_'
            for ii in ['coord', 'box']:
                self.place_holders[ii] = tf.placeholder(
                    GLOBAL_NP_FLOAT_PRECISION, [None, None],
                    name=name_pfx + 't_' + ii)
            self.place_holders['type'] = tf.placeholder(tf.int32, [None, None],
                                                        name=name_pfx +
                                                        't_type')
            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.prod_env_mat_r(self.place_holders['coord'],
                                         self.place_holders['type'],
                                         self.place_holders['natoms_vec'],
                                         self.place_holders['box'],
                                         self.place_holders['default_mesh'],
                                         tf.constant(avg_zero),
                                         tf.constant(std_ones),
                                         rcut = self.rcut,
                                         rcut_smth = self.rcut_smth,
                                         sel = self.sel_r)
            self.sub_sess = tf.Session(graph=sub_graph,
                                       config=default_tf_session_config)
Exemplo n.º 24
0
    def __init__(self,
                 rcut: float,
                 rcut_smth: float,
                 sel: List[str],
                 neuron: List[int] = [24, 48, 96],
                 axis_neuron: int = 8,
                 resnet_dt: bool = False,
                 trainable: bool = True,
                 seed: int = None,
                 type_one_side: bool = True,
                 exclude_types: List[List[int]] = [],
                 set_davg_zero: bool = False,
                 activation_function: str = 'tanh',
                 precision: str = 'default',
                 uniform_seed: bool = False) -> None:
        """
        Constructor
        """
        if rcut < rcut_smth:
            raise RuntimeError(
                "rcut_smth (%f) should be no more than rcut (%f)!" %
                (rcut_smth, rcut))
        self.sel_a = sel
        self.rcut_r = rcut
        self.rcut_r_smth = rcut_smth
        self.filter_neuron = neuron
        self.n_axis_neuron = axis_neuron
        self.filter_resnet_dt = resnet_dt
        self.seed = seed
        self.uniform_seed = uniform_seed
        self.seed_shift = embedding_net_rand_seed_shift(self.filter_neuron)
        self.trainable = trainable
        self.compress_activation_fn = get_activation_func(activation_function)
        self.filter_activation_fn = get_activation_func(activation_function)
        self.filter_precision = get_precision(precision)
        self.exclude_types = set()
        for tt in exclude_types:
            assert (len(tt) == 2)
            self.exclude_types.add((tt[0], tt[1]))
            self.exclude_types.add((tt[1], tt[0]))
        self.set_davg_zero = set_davg_zero
        self.type_one_side = type_one_side

        # descrpt config
        self.sel_r = [0 for ii in range(len(self.sel_a))]
        self.ntypes = len(self.sel_a)
        assert (self.ntypes == len(self.sel_r))
        self.rcut_a = -1
        # numb of neighbors and numb of descrptors
        self.nnei_a = np.cumsum(self.sel_a)[-1]
        self.nnei_r = np.cumsum(self.sel_r)[-1]
        self.nnei = self.nnei_a + self.nnei_r
        self.ndescrpt_a = self.nnei_a * 4
        self.ndescrpt_r = self.nnei_r * 1
        self.ndescrpt = self.ndescrpt_a + self.ndescrpt_r
        self.useBN = False
        self.dstd = None
        self.davg = None
        self.compress = False
        self.embedding_net_variables = None
        self.mixed_prec = None
        self.place_holders = {}
        nei_type = np.array([])
        for ii in range(self.ntypes):
            nei_type = np.append(nei_type,
                                 ii * np.ones(self.sel_a[ii]))  # like a mask
        self.nei_type = tf.constant(nei_type, dtype=tf.int32)

        avg_zero = np.zeros([self.ntypes,
                             self.ndescrpt]).astype(GLOBAL_NP_FLOAT_PRECISION)
        std_ones = np.ones([self.ntypes,
                            self.ndescrpt]).astype(GLOBAL_NP_FLOAT_PRECISION)
        sub_graph = tf.Graph()
        with sub_graph.as_default():
            name_pfx = 'd_sea_'
            for ii in ['coord', 'box']:
                self.place_holders[ii] = tf.placeholder(
                    GLOBAL_NP_FLOAT_PRECISION, [None, None],
                    name=name_pfx + 't_' + ii)
            self.place_holders['type'] = tf.placeholder(tf.int32, [None, None],
                                                        name=name_pfx +
                                                        't_type')
            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.prod_env_mat_a(self.place_holders['coord'],
                                         self.place_holders['type'],
                                         self.place_holders['natoms_vec'],
                                         self.place_holders['box'],
                                         self.place_holders['default_mesh'],
                                         tf.constant(avg_zero),
                                         tf.constant(std_ones),
                                         rcut_a = self.rcut_a,
                                         rcut_r = self.rcut_r,
                                         rcut_r_smth = self.rcut_r_smth,
                                         sel_a = self.sel_a,
                                         sel_r = self.sel_r)
        self.sub_sess = tf.Session(graph=sub_graph,
                                   config=default_tf_session_config)
        self.original_sel = None
Exemplo n.º 25
0
 def setUp(self):
     self.sess = self.test_session().__enter__()
     self.nframes = 2
     self.dcoord = [
         12.83, 2.56, 2.18, 12.09, 2.87, 2.74, 00.25, 3.32, 1.68, 3.36,
         3.00, 1.81, 3.51, 2.51, 2.60, 4.27, 3.22, 1.56
     ]
     self.dtype = [0, 1, 1, 0, 1, 1]
     self.dbox = [13., 0., 0., 0., 13., 0., 0., 0., 13.]
     self.dcoord = np.reshape(self.dcoord, [1, -1])
     self.dtype = np.reshape(self.dtype, [1, -1])
     self.dbox = np.reshape(self.dbox, [1, -1])
     self.dcoord = np.tile(self.dcoord, [self.nframes, 1])
     self.dtype = np.tile(self.dtype, [self.nframes, 1])
     self.dbox = np.tile(self.dbox, [self.nframes, 1])
     self.pbc_expected_output = [
         0.12206, 0.12047, 0.01502, -0.01263, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.02167, -0.77271,
         0.32370, 0.58475, 0.99745, 0.41810, 0.75655, -0.49773, 0.10564,
         0.10495, -0.00143, 0.01198, 0.03103, 0.03041, 0.00452, -0.00425,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 1.02167, 0.77271, -0.32370, -0.58475,
         0.04135, 0.04039, 0.00123, -0.00880, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.59220, 0.42028, 0.16304, -0.38405, 0.03694, 0.03680,
         -0.00300, -0.00117, 0.00336, 0.00327, 0.00022, -0.00074, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.99745,
         -0.41810, -0.75655, 0.49773, 0.19078, 0.18961, -0.01951, 0.00793,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.59220, -0.42028, -0.16304,
         0.38405, 0.13499, 0.12636, -0.03140, 0.03566, 0.07054, 0.07049,
         -0.00175, -0.00210, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.12206, -0.12047, -0.01502, 0.01263, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         1.06176, 0.16913, -0.55250, 0.89077, 1.03163, 0.96880, 0.23422,
         -0.26615, 0.19078, -0.18961, 0.01951, -0.00793, 0.04135, -0.04039,
         -0.00123, 0.00880, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.06176, -0.16913,
         0.55250, -0.89077, 0.10564, -0.10495, 0.00143, -0.01198, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.66798, 0.34516, 0.32245, -0.47232,
         0.13499, -0.12636, 0.03140, -0.03566, 0.03694, -0.03680, 0.00300,
         0.00117, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 1.03163, -0.96880, -0.23422, 0.26615, 0.03103, -0.03041,
         -0.00452, 0.00425, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.66798,
         -0.34516, -0.32245, 0.47232, 0.07054, -0.07049, 0.00175, 0.00210,
         0.00336, -0.00327, -0.00022, 0.00074, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000
     ]
     self.nopbc_expected_output = [
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.02167, -0.77271,
         0.32370, 0.58475, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 1.02167, 0.77271, -0.32370, -0.58475,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.19078,
         0.18961, -0.01951, 0.00793, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.13499, 0.12636, -0.03140,
         0.03566, 0.07054, 0.07049, -0.00175, -0.00210, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         1.06176, 0.16913, -0.55250, 0.89077, 1.03163, 0.96880, 0.23422,
         -0.26615, 0.19078, -0.18961, 0.01951, -0.00793, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.06176, -0.16913,
         0.55250, -0.89077, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.66798, 0.34516, 0.32245, -0.47232,
         0.13499, -0.12636, 0.03140, -0.03566, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 1.03163, -0.96880, -0.23422, 0.26615, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.66798,
         -0.34516, -0.32245, 0.47232, 0.07054, -0.07049, 0.00175, 0.00210,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
         0.00000, 0.00000, 0.00000, 0.00000
     ]
     self.sel = [10, 10]
     self.sec = np.array([0, 0, 0], dtype=int)
     self.sec[1:3] = np.cumsum(self.sel)
     self.rcut = 6.
     self.rcut_smth = 0.8
     self.dnatoms = [6, 6, 2, 4]
     self.tcoord = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION,
                                  [None, self.dnatoms[0] * 3],
                                  name='t_coord')
     self.tbox = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None, 9],
                                name='t_box')
     self.ttype = tf.placeholder(tf.int32, [None, self.dnatoms[0]],
                                 name="t_type")
     self.tnatoms = tf.placeholder(tf.int32, [None], name="t_natoms")
     self.nloc = self.dnatoms[0]
     self.nall = self.dnatoms[1]
     self.nnei = self.sec[-1]
     self.ndescrpt = 4 * self.nnei
     self.ntypes = np.max(self.dtype) + 1
     davg = np.zeros([self.ntypes, self.ndescrpt])
     dstd = np.ones([self.ntypes, self.ndescrpt])
     self.t_avg = tf.constant(davg.astype(GLOBAL_NP_FLOAT_PRECISION))
     self.t_std = tf.constant(dstd.astype(GLOBAL_NP_FLOAT_PRECISION))
Exemplo n.º 26
0
    def setUp(self):
        config = tf.ConfigProto()
        if int(os.environ.get("DP_AUTO_PARALLELIZATION", 0)):
            config.graph_options.rewrite_options.custom_optimizers.add(
            ).name = "dpparallel"
        self.sess = self.test_session(config=config).__enter__()
        self.nframes = 2
        self.dcoord = [
            12.83, 2.56, 2.18, 12.09, 2.87, 2.74, 00.25, 3.32, 1.68, 3.36,
            3.00, 1.81, 3.51, 2.51, 2.60, 4.27, 3.22, 1.56
        ]
        self.dtype = [0, 1, 1, 0, 1, 1]
        self.dbox = [13., 0., 0., 0., 13., 0., 0., 0., 13.]
        self.dnlist = [
            33, -1, -1, -1, -1, 1, 32, 34, 35, -1, 0, 33, -1, -1, -1, 32, 34,
            35, -1, -1, 6, 3, -1, -1, -1, 7, 4, 5, -1, -1, 6, -1, -1, -1, -1,
            4, 5, 2, 7, -1, 3, 6, -1, -1, -1, 5, 2, 7, -1, -1, 3, 6, -1, -1,
            -1, 4, 2, 7, -1, -1
        ]
        self.dem_deriv = [
            0.13227682739491875, 0.01648776318803519, -0.013864709953575083,
            0.12967498112414713, 0.0204174282700489, -0.017169201045268437,
            0.0204174282700489, -0.031583528930688706, -0.0021400703852459233,
            -0.01716920104526844, -0.0021400703852459233, -0.03232887285478848,
            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.7946522798827726,
            0.33289487400494444, 0.6013584820734476, 0.15412158847174678,
            -0.502001299580599, -0.9068410573068878, -0.502001299580599,
            -0.833906252681877, 0.3798928753582899, -0.9068410573068878,
            0.3798928753582899, -0.3579459969766471, 0.4206262499369199,
            0.761133214171572, -0.5007455356391932, -0.6442543005863454,
            0.635525177045359, -0.4181086691087898, 0.6355251770453592,
            0.15453235677768898, -0.75657759172067, -0.4181086691087898,
            -0.75657759172067, -0.49771716703202185, 0.12240657396947655,
            -0.0016631327984983461, 0.013970315507385892, 0.12123416269111335,
            -0.0020346719145638054, 0.017091244082335703,
            -0.002034671914563806, -0.028490045221941415,
            -0.00023221799024912971, 0.017091244082335703,
            -0.00023221799024912971, -0.026567059102687942,
            0.057945707686107975, 0.008613551142529565, -0.008091517739952026,
            0.056503423854730866, 0.009417127630974357, -0.008846392623036528,
            0.009417127630974357, -0.005448318729873151,
            -0.0013150043088297543, -0.008846392623036528,
            -0.0013150043088297541, -0.005612854948377751, 0.0, 0.0, 0.0, 0.0,
            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.7946522798827726,
            -0.33289487400494444, -0.6013584820734476, 0.15412158847174678,
            -0.502001299580599, -0.9068410573068878, -0.502001299580599,
            -0.833906252681877, 0.3798928753582899, -0.9068410573068878,
            0.3798928753582899, -0.3579459969766471, 0.06884320605436924,
            0.002095928989945659, -0.01499395354345747, 0.0668001797461137,
            0.0023216922720068383, -0.016609029330510533,
            0.0023216922720068383, -0.009387797963986713,
            -0.0005056613145120282, -0.016609029330510533,
            -0.0005056613145120282, -0.005841058553679004, 0.0, 0.0, 0.0, 0.0,
            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.3025931001933299,
            0.11738525438534331, -0.2765074881076981, 0.034913562192579815,
            0.15409432322878, -0.3629777391611269, 0.15409432322878003,
            -0.30252938969021487, -0.14081032984698866, -0.3629777391611269,
            -0.14081032984698866, -0.030620805157591004, 0.06555082496658332,
            -0.005338981218997747, -0.002076270474054677, 0.06523884623439505,
            -0.00599162877720186, -0.0023300778578007205, -0.00599162877720186,
            -0.007837034455273667, 0.00018978009701544363,
            -0.0023300778578007205, 0.00018978009701544363,
            -0.008251237047966105, 0.014091999096200191, 0.0009521621010946066,
            -0.00321014651226182, 0.013676554858123476, 0.0009667394698497006,
            -0.0032592930697789946, 0.0009667394698497006,
            -0.0005658690612028018, -0.00022022250471479668,
            -0.0032592930697789937, -0.00022022250471479666,
            0.00011127514881492382, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
            0.0, 0.0, 0.0, -0.4206262499369199, -0.761133214171572,
            0.5007455356391932, -0.6442543005863454, 0.635525177045359,
            -0.4181086691087898, 0.6355251770453592, 0.15453235677768898,
            -0.75657759172067, -0.4181086691087898, -0.75657759172067,
            -0.49771716703202185, 0.17265177804411166, -0.01776481317495682,
            0.007216955352326217, 0.1708538944675734, -0.023853120077098278,
            0.009690330031321191, -0.02385312007709828, -0.05851427595224925,
            -0.0009970757588497682, 0.00969033003132119,
            -0.0009970757588497682, -0.06056355425469288, 0.0, 0.0, 0.0, 0.0,
            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.3025931001933299,
            -0.11738525438534331, 0.2765074881076981, 0.034913562192579815,
            0.15409432322878, -0.3629777391611269, 0.15409432322878003,
            -0.30252938969021487, -0.14081032984698866, -0.3629777391611269,
            -0.14081032984698866, -0.030620805157591004, 0.13298898711407747,
            -0.03304327593938735, 0.03753063440029181, 0.11967949867634801,
            -0.0393666881596552, 0.044712781613435545, -0.0393666881596552,
            -0.02897797727002851, -0.01110961751744871, 0.044712781613435545,
            -0.011109617517448708, -0.026140939946396612, 0.09709214772325653,
            -0.00241522755530488, -0.0028982730663658636, 0.09699249715361474,
            -0.0028489422636695603, -0.0034187307164034813,
            -0.00284894226366956, -0.017464112635362926, 8.504305264685245e-05,
            -0.003418730716403481, 8.504305264685245e-05,
            -0.017432930182725747, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
            0.0, 0.0, -0.1322768273949186, -0.016487763188035173,
            0.013864709953575069, 0.12967498112414702, 0.020417428270048884,
            -0.017169201045268423, 0.02041742827004888, -0.03158352893068868,
            -0.002140070385245921, -0.017169201045268423,
            -0.002140070385245921, -0.03232887285478844, 0.0, 0.0, 0.0, 0.0,
            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
            0.0, 0.0, 0.0, 0.0, 0.0, 0.1802999914938216, -0.5889799722131493,
            0.9495799552007915, -1.070225697321266, -0.18728687322613707,
            0.30195230581356786, -0.18728687322613707, -0.5157546277429348,
            -0.9863775323243197, 0.30195230581356786, -0.9863775323243197,
            0.4627237303364723, 1.0053013143052718, 0.24303987818369216,
            -0.2761816797541954, 0.8183357773897718, 0.45521877564245394,
            -0.517294063230061, 0.45521877564245394, -0.9545617219529918,
            -0.1250601031984763, -0.517294063230061, -0.1250601031984763,
            -0.922500859133019, -0.17265177804411166, 0.01776481317495682,
            -0.007216955352326217, 0.1708538944675734, -0.023853120077098278,
            0.009690330031321191, -0.02385312007709828, -0.05851427595224925,
            -0.0009970757588497682, 0.00969033003132119,
            -0.0009970757588497682, -0.06056355425469288, -0.06884320605436924,
            -0.002095928989945659, 0.01499395354345747, 0.0668001797461137,
            0.0023216922720068383, -0.016609029330510533,
            0.0023216922720068383, -0.009387797963986713,
            -0.0005056613145120282, -0.016609029330510533,
            -0.0005056613145120282, -0.005841058553679004, 0.0, 0.0, 0.0, 0.0,
            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.1802999914938216,
            0.5889799722131493, -0.9495799552007915, -1.070225697321266,
            -0.18728687322613707, 0.30195230581356786, -0.18728687322613707,
            -0.5157546277429348, -0.9863775323243197, 0.30195230581356786,
            -0.9863775323243197, 0.4627237303364723, -0.12240657396947667,
            0.0016631327984983487, -0.013970315507385913, 0.12123416269111348,
            -0.002034671914563809, 0.01709124408233573, -0.002034671914563809,
            -0.028490045221941467, -0.00023221799024913015,
            0.01709124408233573, -0.00023221799024913015,
            -0.026567059102687987, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
            0.0, 0.2602591506940697, 0.24313683814840728, -0.3561441009497795,
            -0.19841405298242495, 0.23891499072173572, -0.3499599864093028,
            0.23891499072173572, -0.23095714382387694, -0.32693630309290145,
            -0.34995998640930287, -0.32693630309290145, 0.02473856993038946,
            -0.13298898711407747, 0.03304327593938735, -0.03753063440029181,
            0.11967949867634801, -0.0393666881596552, 0.044712781613435545,
            -0.0393666881596552, -0.02897797727002851, -0.01110961751744871,
            0.044712781613435545, -0.011109617517448708, -0.026140939946396612,
            -0.0655508249665835, 0.005338981218997763, 0.002076270474054683,
            0.0652388462343952, -0.005991628777201879, -0.0023300778578007283,
            -0.005991628777201879, -0.007837034455273709,
            0.0001897800970154443, -0.002330077857800728,
            0.0001897800970154443, -0.008251237047966148, 0.0, 0.0, 0.0, 0.0,
            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0053013143052718,
            -0.24303987818369216, 0.2761816797541954, 0.8183357773897718,
            0.45521877564245394, -0.517294063230061, 0.45521877564245394,
            -0.9545617219529918, -0.1250601031984763, -0.517294063230061,
            -0.1250601031984763, -0.922500859133019, -0.057945707686107864,
            -0.008613551142529548, 0.00809151773995201, 0.05650342385473076,
            0.009417127630974336, -0.00884639262303651, 0.009417127630974336,
            -0.005448318729873148, -0.0013150043088297515,
            -0.00884639262303651, -0.0013150043088297513,
            -0.005612854948377747, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
            0.0, -0.2602591506940697, -0.24313683814840728, 0.3561441009497795,
            -0.19841405298242495, 0.23891499072173572, -0.3499599864093028,
            0.23891499072173572, -0.23095714382387694, -0.32693630309290145,
            -0.34995998640930287, -0.32693630309290145, 0.02473856993038946,
            -0.09709214772325653, 0.00241522755530488, 0.0028982730663658636,
            0.09699249715361474, -0.0028489422636695603,
            -0.0034187307164034813, -0.00284894226366956,
            -0.017464112635362926, 8.504305264685245e-05,
            -0.003418730716403481, 8.504305264685245e-05,
            -0.017432930182725747, -0.014091999096200191,
            -0.0009521621010946064, 0.0032101465122618194,
            0.013676554858123474, 0.0009667394698497003,
            -0.0032592930697789933, 0.0009667394698497003,
            -0.0005658690612028016, -0.0002202225047147966,
            -0.0032592930697789933, -0.0002202225047147966,
            0.00011127514881492362, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
            0.0, 0.0, 0.0
        ]
        self.dcoord = np.reshape(self.dcoord, [1, -1])
        self.dtype = np.reshape(self.dtype, [1, -1])
        self.dbox = np.reshape(self.dbox, [1, -1])
        self.dnlist = np.reshape(self.dnlist, [1, -1])
        self.dem_deriv = np.reshape(self.dem_deriv, [1, -1])
        self.dcoord = np.tile(self.dcoord, [self.nframes, 1])
        self.dtype = np.tile(self.dtype, [self.nframes, 1])
        self.dbox = np.tile(self.dbox, [self.nframes, 1])
        self.dnlist = np.tile(self.dnlist, [self.nframes, 1])
        self.dem_deriv = np.tile(self.dem_deriv, [self.nframes, 1])
        self.expected_force = [
            9.44498, -13.86254, 10.52884, -19.42688, 8.09273, 19.64478,
            4.81771, 11.39255, 12.38830, -16.65832, 6.65153, -10.15585,
            1.16660, -14.43259, 22.97076, 22.86479, 7.42726, -11.41943,
            -7.67893, -7.23287, -11.33442, -4.51184, -3.80588, -2.44935,
            0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
            0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
            0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
            0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
            0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
            0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
            0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
            0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
            0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
            0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
            0.00000, 0.00000, 1.16217, 6.16192, -28.79094, 3.81076, -0.01986,
            -1.01629, 3.65869, -0.49195, -0.07437, 1.35028, 0.11969, -0.29201,
            0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
            0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
            0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
            0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
            0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
            0.00000
        ]

        self.sel = [5, 5]
        self.sec = np.array([0, 0, 0], dtype=int)
        self.sec[1:3] = np.cumsum(self.sel)
        self.rcut = 6.
        self.rcut_smth = 0.8
        self.dnatoms = [6, 48, 2, 4]

        self.nloc = self.dnatoms[0]
        self.nall = self.dnatoms[1]
        self.nnei = self.sec[-1]
        self.ndescrpt = 4 * self.nnei
        self.ntypes = np.max(self.dtype) + 1
        self.dnet_deriv = []
        for ii in range(self.nloc * self.ndescrpt):
            self.dnet_deriv.append(10 - ii * 0.01)
        self.dnet_deriv = np.reshape(self.dnet_deriv, [1, -1])
        self.dnet_deriv = np.tile(self.dnet_deriv, [self.nframes, 1])

        self.tnet_deriv = tf.placeholder(
            GLOBAL_TF_FLOAT_PRECISION, [None, self.dnatoms[0] * self.ndescrpt],
            name='t_net_deriv')
        self.tem_deriv = tf.placeholder(
            GLOBAL_TF_FLOAT_PRECISION,
            [None, self.dnatoms[0] * self.ndescrpt * 3],
            name='t_em_deriv')
        self.tnlist = tf.placeholder(tf.int32,
                                     [None, self.dnatoms[0] * self.nnei],
                                     name="t_nlist")
        self.tnatoms = tf.placeholder(tf.int32, [None], name="t_natoms")
Exemplo n.º 27
0
    def test_model(self):
        jfile = 'wfc.json'
        with open(jfile) as fp:
            jdata = json.load(fp)
        run_opt = RunOptions(None)
        systems = j_must_have(jdata, 'systems')
        set_pfx = j_must_have(jdata, 'set_prefix')
        batch_size = j_must_have(jdata, 'batch_size')
        test_size = j_must_have(jdata, 'numb_test')
        batch_size = 1
        test_size = 1
        stop_batch = j_must_have(jdata, 'stop_batch')
        rcut = j_must_have(jdata['model']['descriptor'], 'rcut')

        data = DataSystem(systems,
                          set_pfx,
                          batch_size,
                          test_size,
                          rcut,
                          run_opt=None)

        test_data = data.get_test()
        numb_test = 1

        descrpt = DescrptLocFrame(jdata['model']['descriptor'])
        fitting = WFCFitting(jdata['model']['fitting_net'], descrpt)
        model = WFCModel(jdata['model'], descrpt, fitting)

        input_data = {
            'coord': [test_data['coord']],
            'box': [test_data['box']],
            'type': [test_data['type']],
            'natoms_vec': [test_data['natoms_vec']],
            'default_mesh': [test_data['default_mesh']],
            'fparam': [test_data['fparam']],
        }
        model._compute_dstats(input_data)

        t_prop_c = tf.placeholder(tf.float32, [5], name='t_prop_c')
        t_energy = tf.placeholder(global_ener_float_precision, [None],
                                  name='t_energy')
        t_force = tf.placeholder(global_tf_float_precision, [None],
                                 name='t_force')
        t_virial = tf.placeholder(global_tf_float_precision, [None],
                                  name='t_virial')
        t_atom_ener = tf.placeholder(global_tf_float_precision, [None],
                                     name='t_atom_ener')
        t_coord = tf.placeholder(global_tf_float_precision, [None],
                                 name='i_coord')
        t_type = tf.placeholder(tf.int32, [None], name='i_type')
        t_natoms = tf.placeholder(tf.int32, [model.ntypes + 2],
                                  name='i_natoms')
        t_box = tf.placeholder(global_tf_float_precision, [None, 9],
                               name='i_box')
        t_mesh = tf.placeholder(tf.int32, [None], name='i_mesh')
        is_training = tf.placeholder(tf.bool)
        t_fparam = None

        model_pred \
            = model.build (t_coord,
                           t_type,
                           t_natoms,
                           t_box,
                           t_mesh,
                           t_fparam,
                           suffix = "wfc",
                           reuse = False)
        wfc = model_pred['wfc']

        feed_dict_test = {
            t_prop_c: test_data['prop_c'],
            t_coord: np.reshape(test_data['coord'][:numb_test, :], [-1]),
            t_box: test_data['box'][:numb_test, :],
            t_type: np.reshape(test_data['type'][:numb_test, :], [-1]),
            t_natoms: test_data['natoms_vec'],
            t_mesh: test_data['default_mesh'],
            is_training: False
        }

        sess = tf.Session()
        sess.run(tf.global_variables_initializer())
        [p] = sess.run([wfc], feed_dict=feed_dict_test)

        p = p.reshape([-1])
        refp = [
            -9.105016838228578990e-01, 7.196284362034099935e-01,
            -9.548516928185298014e-02, 2.764615027095288724e+00,
            2.661319598995644520e-01, 7.579512949131941846e-02,
            -2.107409067376114997e+00, -1.299080016614967414e-01,
            -5.962778584850070285e-01, 2.913899917663253514e-01,
            -1.226917174638697094e+00, 1.829523069930876655e+00,
            1.015704024959750873e+00, -1.792333611099589386e-01,
            5.032898080485321834e-01, 1.808561721292949453e-01,
            2.468863482075112081e+00, -2.566442546384765100e-01,
            -1.467453783795173994e-01, -1.822963931552128658e+00,
            5.843600156865462747e-01, -1.493875280832117403e+00,
            1.693322352814763398e-01, -1.877325443995481624e+00
        ]

        places = 6
        for ii in range(p.size):
            self.assertAlmostEqual(p[ii], refp[ii], places=places)
Exemplo n.º 28
0
    def test_descriptor_one_side(self):
        jfile = 'water_se_a_type.json'
        jdata = j_loader(jfile)

        systems = j_must_have(jdata, 'systems')
        set_pfx = j_must_have(jdata, 'set_prefix')
        batch_size = j_must_have(jdata, 'batch_size')
        test_size = j_must_have(jdata, 'numb_test')
        batch_size = 1
        test_size = 1
        stop_batch = j_must_have(jdata, 'stop_batch')
        rcut = j_must_have(jdata['model']['descriptor'], 'rcut')
        sel = j_must_have(jdata['model']['descriptor'], 'sel')
        ntypes = len(sel)

        data = DataSystem(systems,
                          set_pfx,
                          batch_size,
                          test_size,
                          rcut,
                          run_opt=None)

        test_data = data.get_test()
        numb_test = 1

        # set parameters
        jdata['model']['descriptor']['neuron'] = [5, 5, 5]
        jdata['model']['descriptor']['axis_neuron'] = 2
        jdata['model']['descriptor']['type_one_side'] = True
        typeebd_param = {
            'neuron': [5, 5, 5],
            'resnet_dt': False,
            'seed': 1,
        }

        # init models
        typeebd = TypeEmbedNet(neuron=typeebd_param['neuron'],
                               resnet_dt=typeebd_param['resnet_dt'],
                               seed=typeebd_param['seed'],
                               uniform_seed=True)

        jdata['model']['descriptor'].pop('type', None)
        descrpt = DescrptSeA(**jdata['model']['descriptor'], uniform_seed=True)

        # model._compute_dstats([test_data['coord']], [test_data['box']], [test_data['type']], [test_data['natoms_vec']], [test_data['default_mesh']])
        input_data = {
            'coord': [test_data['coord']],
            'box': [test_data['box']],
            'type': [test_data['type']],
            'natoms_vec': [test_data['natoms_vec']],
            'default_mesh': [test_data['default_mesh']]
        }
        descrpt.bias_atom_e = data.compute_energy_shift()

        t_prop_c = tf.placeholder(tf.float32, [5], name='t_prop_c')
        t_energy = tf.placeholder(GLOBAL_ENER_FLOAT_PRECISION, [None],
                                  name='t_energy')
        t_force = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None],
                                 name='t_force')
        t_virial = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None],
                                  name='t_virial')
        t_atom_ener = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None],
                                     name='t_atom_ener')
        t_coord = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None],
                                 name='i_coord')
        t_type = tf.placeholder(tf.int32, [None], name='i_type')
        t_natoms = tf.placeholder(tf.int32, [ntypes + 2], name='i_natoms')
        t_box = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None, 9],
                               name='i_box')
        t_mesh = tf.placeholder(tf.int32, [None], name='i_mesh')
        is_training = tf.placeholder(tf.bool)
        t_fparam = None

        type_embedding = typeebd.build(ntypes,
                                       suffix="_se_a_type_des_ebd_1side")

        dout \
            = descrpt.build(
                t_coord,
                t_type,
                t_natoms,
                t_box,
                t_mesh,
                {'type_embedding' : type_embedding},
                reuse = False,
                suffix = "_se_a_type_des_1side"
            )

        feed_dict_test = {
            t_prop_c: test_data['prop_c'],
            t_energy: test_data['energy'][:numb_test],
            t_force: np.reshape(test_data['force'][:numb_test, :], [-1]),
            t_virial: np.reshape(test_data['virial'][:numb_test, :], [-1]),
            t_atom_ener: np.reshape(test_data['atom_ener'][:numb_test, :],
                                    [-1]),
            t_coord: np.reshape(test_data['coord'][:numb_test, :], [-1]),
            t_box: test_data['box'][:numb_test, :],
            t_type: np.reshape(test_data['type'][:numb_test, :], [-1]),
            t_natoms: test_data['natoms_vec'],
            t_mesh: test_data['default_mesh'],
            is_training: False
        }

        sess = self.test_session().__enter__()
        sess.run(tf.global_variables_initializer())
        [model_dout] = sess.run([dout], feed_dict=feed_dict_test)
        model_dout = model_dout.reshape([-1])

        ref_dout = [
            0.0009704469114440277, 0.0007136310372560243,
            0.0007136310372560243, 0.000524968274824758,
            -0.0019790100690810016, -0.0014556100390424947,
            -0.001318691223889266, -0.0009698525512440269,
            0.001937780602605409, 0.0014251755182315322, 0.0008158935519461114,
            0.0005943870925895051, 0.0005943870925895051,
            0.0004340263490412088, -0.0016539827195947239,
            -0.0012066241021841376, -0.0011042186455562336,
            -0.0008051343572505189, 0.0016229491738044255,
            0.0011833923257801077, 0.0006020440527161554,
            0.00047526899287409847, 0.00047526899287409847,
            0.00037538142786805136, -0.0012811397377036637,
            -0.0010116898098710776, -0.0008465095301785942,
            -0.0006683577463042215, 0.0012459039620461505,
            0.0009836962283627838, 0.00077088529431722, 0.0006105807630364827,
            0.0006105807630364827, 0.00048361458700877996,
            -0.0016444700616024337, -0.001302510079662288,
            -0.0010856603485807576, -0.0008598975276238373,
            0.00159730642327918, 0.001265146946434076, 0.0008495806081447204,
            0.000671787466824433, 0.000671787466824433, 0.0005312928157964384,
            -0.0018105890543181475, -0.001431844407277983,
            -0.0011956722392735362, -0.000945544277375045,
            0.0017590147511761475, 0.0013910348287283414,
            0.0007393644735054756, 0.0005850536182149991,
            0.0005850536182149991, 0.0004631887654949332,
            -0.0015760302086346792, -0.0012475134925387294,
            -0.001041074331192672, -0.0008239586048523492,
            0.0015319673563669856, 0.0012124704278707746
        ]

        places = 10
        np.testing.assert_almost_equal(model_dout, ref_dout, places)
Exemplo n.º 29
0
    def __init__(self, jdata):
        args = ClassArg()\
               .add('sel',      list,   must = True) \
               .add('rcut',     float,  default = 6.0) \
               .add('rcut_smth',float,  default = 5.5) \
               .add('neuron',   list,   default = [10, 20, 40]) \
               .add('axis_neuron', int, default = 4, alias = 'n_axis_neuron') \
               .add('resnet_dt',bool,   default = False) \
               .add('trainable',bool,   default = True) \
               .add('seed',     int) \
               .add('exclude_types', list, default = []) \
               .add('set_davg_zero', bool, default = False) \
               .add('activation_function', str,    default = 'tanh') \
               .add('precision', str, default = "default")
        class_data = args.parse(jdata)
        self.sel_a = class_data['sel']
        self.rcut_r = class_data['rcut']
        self.rcut_r_smth = class_data['rcut_smth']
        self.filter_neuron = class_data['neuron']
        self.n_axis_neuron = class_data['axis_neuron']
        self.filter_resnet_dt = class_data['resnet_dt']
        self.seed = class_data['seed']
        self.trainable = class_data['trainable']
        self.filter_activation_fn = get_activation_func(
            class_data['activation_function'])
        self.filter_precision = get_precision(class_data['precision'])
        exclude_types = class_data['exclude_types']
        self.exclude_types = set()
        for tt in exclude_types:
            assert (len(tt) == 2)
            self.exclude_types.add((tt[0], tt[1]))
            self.exclude_types.add((tt[1], tt[0]))
        self.set_davg_zero = class_data['set_davg_zero']

        # descrpt config
        self.sel_r = [0 for ii in range(len(self.sel_a))]
        self.ntypes = len(self.sel_a)
        assert (self.ntypes == len(self.sel_r))
        self.rcut_a = -1
        # numb of neighbors and numb of descrptors
        self.nnei_a = np.cumsum(self.sel_a)[-1]
        self.nnei_r = np.cumsum(self.sel_r)[-1]
        self.nnei = self.nnei_a + self.nnei_r
        self.ndescrpt_a = self.nnei_a * 4
        self.ndescrpt_r = self.nnei_r * 1
        self.ndescrpt = self.ndescrpt_a + self.ndescrpt_r
        self.useBN = False
        self.dstd = None
        self.davg = None

        self.place_holders = {}
        avg_zero = np.zeros([self.ntypes,
                             self.ndescrpt]).astype(global_np_float_precision)
        std_ones = np.ones([self.ntypes,
                            self.ndescrpt]).astype(global_np_float_precision)
        sub_graph = tf.Graph()
        with sub_graph.as_default():
            name_pfx = 'd_sea_'
            for ii in ['coord', 'box']:
                self.place_holders[ii] = tf.placeholder(
                    global_np_float_precision, [None, None],
                    name=name_pfx + 't_' + ii)
            self.place_holders['type'] = tf.placeholder(tf.int32, [None, None],
                                                        name=name_pfx +
                                                        't_type')
            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'],
                                         self.place_holders['type'],
                                         self.place_holders['natoms_vec'],
                                         self.place_holders['box'],
                                         self.place_holders['default_mesh'],
                                         tf.constant(avg_zero),
                                         tf.constant(std_ones),
                                         rcut_a = self.rcut_a,
                                         rcut_r = self.rcut_r,
                                         rcut_r_smth = self.rcut_r_smth,
                                         sel_a = self.sel_a,
                                         sel_r = self.sel_r)
        self.sub_sess = tf.Session(graph=sub_graph,
                                   config=default_tf_session_config)
Exemplo n.º 30
0
    def test_descriptor_two_sides(self):
        jfile = 'water_se_a_type.json'
        jdata = j_loader(jfile)

        systems = j_must_have(jdata, 'systems')
        set_pfx = j_must_have(jdata, 'set_prefix')
        batch_size = j_must_have(jdata, 'batch_size')
        test_size = j_must_have(jdata, 'numb_test')
        batch_size = 2
        test_size = 1
        stop_batch = j_must_have(jdata, 'stop_batch')
        rcut = j_must_have(jdata['model']['descriptor'], 'rcut')
        sel = j_must_have(jdata['model']['descriptor'], 'sel')
        ntypes = len(sel)

        data = DataSystem(systems,
                          set_pfx,
                          batch_size,
                          test_size,
                          rcut,
                          run_opt=None)

        test_data = data.get_test()
        numb_test = 1

        # set parameters
        jdata['model']['descriptor']['neuron'] = [5, 5, 5]
        jdata['model']['descriptor']['axis_neuron'] = 2
        typeebd_param = {
            'neuron': [5, 5, 5],
            'resnet_dt': False,
            'seed': 1,
        }

        # init models
        typeebd = TypeEmbedNet(neuron=typeebd_param['neuron'],
                               resnet_dt=typeebd_param['resnet_dt'],
                               seed=typeebd_param['seed'],
                               uniform_seed=True)

        jdata['model']['descriptor'].pop('type', None)
        descrpt = DescrptSeA(**jdata['model']['descriptor'], uniform_seed=True)

        # model._compute_dstats([test_data['coord']], [test_data['box']], [test_data['type']], [test_data['natoms_vec']], [test_data['default_mesh']])
        input_data = {
            'coord': [test_data['coord']],
            'box': [test_data['box']],
            'type': [test_data['type']],
            'natoms_vec': [test_data['natoms_vec']],
            'default_mesh': [test_data['default_mesh']]
        }
        descrpt.bias_atom_e = data.compute_energy_shift()

        t_prop_c = tf.placeholder(tf.float32, [5], name='t_prop_c')
        t_energy = tf.placeholder(GLOBAL_ENER_FLOAT_PRECISION, [None],
                                  name='t_energy')
        t_force = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None],
                                 name='t_force')
        t_virial = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None],
                                  name='t_virial')
        t_atom_ener = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None],
                                     name='t_atom_ener')
        t_coord = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None],
                                 name='i_coord')
        t_type = tf.placeholder(tf.int32, [None], name='i_type')
        t_natoms = tf.placeholder(tf.int32, [ntypes + 2], name='i_natoms')
        t_box = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None, 9],
                               name='i_box')
        t_mesh = tf.placeholder(tf.int32, [None], name='i_mesh')
        is_training = tf.placeholder(tf.bool)
        t_fparam = None

        type_embedding = typeebd.build(ntypes,
                                       suffix="_se_a_type_des_ebd_2sdies")

        dout \
            = descrpt.build(
                t_coord,
                t_type,
                t_natoms,
                t_box,
                t_mesh,
                {'type_embedding' : type_embedding},
                reuse = False,
                suffix = "_se_a_type_des_2sides"
            )

        feed_dict_test = {
            t_prop_c: test_data['prop_c'],
            t_energy: test_data['energy'][:numb_test],
            t_force: np.reshape(test_data['force'][:numb_test, :], [-1]),
            t_virial: np.reshape(test_data['virial'][:numb_test, :], [-1]),
            t_atom_ener: np.reshape(test_data['atom_ener'][:numb_test, :],
                                    [-1]),
            t_coord: np.reshape(test_data['coord'][:numb_test, :], [-1]),
            t_box: test_data['box'][:numb_test, :],
            t_type: np.reshape(test_data['type'][:numb_test, :], [-1]),
            t_natoms: test_data['natoms_vec'],
            t_mesh: test_data['default_mesh'],
            is_training: False
        }

        sess = self.test_session().__enter__()
        sess.run(tf.global_variables_initializer())
        [model_dout] = sess.run([dout], feed_dict=feed_dict_test)
        model_dout = model_dout.reshape([-1])

        ref_dout = [
            0.0005722682145569174, -0.00020202686217742682,
            -0.00020202686217742682, 7.13250554992363e-05,
            -0.0014770058171250015, 0.000521468690207748,
            -0.001143865186937176, 0.0004038453384193948,
            0.0005617335409639567, -0.00019831394075147532,
            0.00048086740718842236, -0.0001693584775806112,
            -0.0001693584775806112, 5.966987137476082e-05,
            -0.0012342029581315136, 0.00043492340851472783,
            -0.0009566016612537016, 0.00033706767041080107,
            0.00047065988464132244, -0.0001657950398095401,
            0.0003647849239740657, -0.00013744939018250384,
            -0.00013744939018250384, 5.1825826955234744e-05,
            -0.00096004206555711, 0.00036185565262332876,
            -0.0007267433909643961, 0.0002738914365542745,
            0.00038019365906978136, -0.00014322754331896057,
            0.0004675256930823109, -0.00017634410399626168,
            -0.00017634410399626168, 6.652672908755666e-05,
            -0.0012328062885292486, 0.00046500213384094614,
            -0.0009328887521346069, 0.0003518668613172834,
            0.0004877847509912577, -0.00018396318824508986,
            0.0005154794374703516, -0.00019422534512034776,
            -0.00019422534512034776, 7.318151797939947e-05,
            -0.0013576642997136488, 0.0005115548790018505,
            -0.0010275333676074971, 0.00038716440070070385,
            0.0005376426714609369, -0.00020257810468163985,
            0.0004482204892297628, -0.00016887749501640607,
            -0.00016887749501640607, 6.364643102775375e-05,
            -0.001181345877677835, 0.0004452029242063362,
            -0.0008941636427724908, 0.0003369586197174627,
            0.0004677878512312651, -0.00017625260641095753
        ]

        places = 10
        np.testing.assert_almost_equal(model_dout, ref_dout, places)