def setUpClass(self):
     self.dp_original = DeepPot(FROZEN_MODEL)
     self.dp_compressed = DeepPot(COMPRESSED_MODEL)
     self.coords = np.array([
         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.atype = [0, 1, 1, 0, 1, 1]
     self.box = np.array([13., 0., 0., 0., 13., 0., 0., 0., 13.])
Ejemplo n.º 2
0
 def setUp(self):
     convert_pbtxt_to_pb(
         str(tests_path / os.path.join("infer", "deeppot.pbtxt")),
         "deeppot.pb")
     self.dp = DeepPot("deeppot.pb")
     self.coords = np.array([
         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.atype = [0, 1, 1, 0, 1, 1]
     self.box = np.array([13., 0., 0., 0., 13., 0., 0., 0., 13.])
     self.expected_e = np.array([
         -9.275780747115504710e+01, -1.863501786584258468e+02,
         -1.863392472863538103e+02, -9.279281325486221021e+01,
         -1.863671545232153903e+02, -1.863619822847602165e+02
     ])
     self.expected_f = np.array([
         -3.034045420701179663e-01, 8.405844663871177014e-01,
         7.696947487118485642e-02, 7.662001266663505117e-01,
         -1.880601391333554251e-01, -6.183333871091722944e-01,
         -5.036172391059643427e-01, -6.529525836149027151e-01,
         5.432962643022043459e-01, 6.382357912332115024e-01,
         -1.748518296794561167e-01, 3.457363524891907125e-01,
         1.286482986991941552e-03, 3.757251165286925043e-01,
         -5.972588700887541124e-01, -5.987006197104716154e-01,
         -2.004450304880958100e-01, 2.495901655353461868e-01
     ])
     self.expected_v = np.array([
         -2.912234126853306959e-01, -3.800610846612756388e-02,
         2.776624987489437202e-01, -5.053761003913598976e-02,
         -3.152373041953385746e-01, 1.060894290092162379e-01,
         2.826389131596073745e-01, 1.039129970665329250e-01,
         -2.584378792325942586e-01, -3.121722367954994914e-01,
         8.483275876786681990e-02, 2.524662342344257682e-01,
         4.142176771106586414e-02, -3.820285230785245428e-02,
         -2.727311173065460545e-02, 2.668859789777112135e-01,
         -6.448243569420382404e-02, -2.121731470426218846e-01,
         -8.624335220278558922e-02, -1.809695356746038597e-01,
         1.529875294531883312e-01, -1.283658185172031341e-01,
         -1.992682279795223999e-01, 1.409924999632362341e-01,
         1.398322735274434292e-01, 1.804318474574856390e-01,
         -1.470309318999652726e-01, -2.593983661598450730e-01,
         -4.236536279233147489e-02, 3.386387920184946720e-02,
         -4.174017537818433543e-02, -1.003500282164128260e-01,
         1.525690815194478966e-01, 3.398976109910181037e-02,
         1.522253908435125536e-01, -2.349125581341701963e-01,
         9.515545977581392825e-04, -1.643218849228543846e-02,
         1.993234765412972564e-02, 6.027265332209678569e-04,
         -9.563256398907417355e-02, 1.510815124001868293e-01,
         -7.738094816888557714e-03, 1.502832772532304295e-01,
         -2.380965783745832010e-01, -2.309456719810296654e-01,
         -6.666961081213038098e-02, 7.955566551234216632e-02,
         -8.099093777937517447e-02, -3.386641099800401927e-02,
         4.447884755740908608e-02, 1.008593228579038742e-01,
         4.556718179228393811e-02, -6.078081273849572641e-02
     ])
Ejemplo n.º 3
0
 def setUp(self):
     convert_pbtxt_to_pb(
         str(tests_path / os.path.join("infer", "deeppot-r.pbtxt")),
         "deeppot.pb")
     self.dp = DeepPot("deeppot.pb")
     self.coords = np.array([
         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.atype = [0, 1, 1, 0, 1, 1]
     self.box = np.array([19., 0., 0., 0., 13., 0., 0., 0., 13.])
     self.expected_e = np.array([
         -9.321213823508108476e+01, -1.868044102481340758e+02,
         -1.868067983858651075e+02, -9.320899631301440991e+01,
         -1.868014559732615112e+02, -1.868017660713088617e+02
     ])
     self.expected_f = np.array([
         4.578151103701261042e-03, -1.917874111009987628e-03,
         -3.464546781179331930e-03, -4.578151103701261042e-03,
         1.917874111009987628e-03, 3.464546781179331930e-03,
         -2.624402581721222913e-03, 3.566275128489623933e-04,
         -2.859315986763691776e-04, -5.767787273464367384e-03,
         1.907053583551196647e-03, -3.889064429673861831e-03,
         1.786820066350549132e-04, -5.327197473636275694e-03,
         8.236236182834734409e-03, 8.213507848550535492e-03,
         3.063516377236116545e-03, -4.061240154484504865e-03
     ])
     self.expected_v = np.array([
         1.984979026299632174e-03, -8.315452677741701822e-04,
         -1.502146290172694243e-03, -8.315452677741700738e-04,
         3.483500446080982317e-04, 6.292774999372096039e-04,
         -1.502146290172694243e-03, 6.292774999372097123e-04,
         1.136759354725281907e-03, 1.402852790439301908e-03,
         -5.876815743732210226e-04, -1.061618327900012114e-03,
         -5.876815743732211311e-04, 2.461909298049979960e-04,
         4.447320022283834766e-04, -1.061618327900012331e-03,
         4.447320022283834766e-04, 8.033868427351443728e-04,
         4.143606961846296385e-03, -5.511382161123719835e-04,
         4.465413399437045397e-04, -5.511382161123719835e-04,
         1.082271054025323839e-04, -1.097918001262628728e-04,
         4.465413399437046481e-04, -1.097918001262628728e-04,
         1.220966982358671871e-04, 5.263952004497593831e-03,
         2.395243710938091842e-04, -2.830378939414603329e-04,
         2.395243710938094010e-04, 1.189969706598244898e-03,
         -1.805627331015851201e-03, -2.830378939414602245e-04,
         -1.805627331015851635e-03, 2.801996513751836820e-03,
         2.208413501170402270e-03, 5.331756287635716889e-05,
         -1.664423506603235218e-04, 5.331756287635695205e-05,
         1.379626072862918072e-03, -2.094132943741625064e-03,
         -1.664423506603234133e-04, -2.094132943741625064e-03,
         3.199787996743366607e-03, 4.047014004814953811e-03,
         1.137904999421357000e-03, -1.568106936614101698e-03,
         1.137904999421357217e-03, 7.205982843216952307e-04,
         -1.011174600268313238e-03, -1.568106936614101698e-03,
         -1.011174600268313238e-03, 1.435226522157425754e-03
     ])
Ejemplo n.º 4
0
 def setUp(self):
     convert_pbtxt_to_pb(
         str(tests_path / os.path.join("infer", "deeppot.pbtxt")),
         "deeppot.pb")
     self.dp = DeepPot("deeppot.pb")
     self.coords = np.array([
         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.atype = [0, 1, 1, 0, 1, 1]
     self.box = np.array([19., 0., 0., 0., 13., 0., 0., 0., 13.])
     self.expected_e = np.array([
         -9.255934839310273787e+01, -1.863253376736990106e+02,
         -1.857237299341402945e+02, -9.279308539717486326e+01,
         -1.863708105823244239e+02, -1.863635196514972563e+02
     ])
     self.expected_f = np.array([
         -2.161037360255332107e+00, 9.052994347015581589e-01,
         1.635379623977007979e+00, 2.161037360255332107e+00,
         -9.052994347015581589e-01, -1.635379623977007979e+00,
         -1.167128117249453811e-02, 1.371975700096064992e-03,
         -1.575265180249604477e-03, 6.226508593971802341e-01,
         -1.816734122009256991e-01, 3.561766019664774907e-01,
         -1.406075393906316626e-02, 3.789140061530929526e-01,
         -6.018777878642909140e-01, -5.969188242856223736e-01,
         -1.986125696522633155e-01, 2.472764510780630642e-01
     ])
     self.expected_v = np.array([
         -7.042445481792056761e-01, 2.950213647777754078e-01,
         5.329418202437231633e-01, 2.950213647777752968e-01,
         -1.235900311906896754e-01, -2.232594111831812944e-01,
         5.329418202437232743e-01, -2.232594111831813499e-01,
         -4.033073234276823849e-01, -8.949230984097404917e-01,
         3.749002169013777030e-01, 6.772391014992630298e-01,
         3.749002169013777586e-01, -1.570527935667933583e-01,
         -2.837082722496912512e-01, 6.772391014992631408e-01,
         -2.837082722496912512e-01, -5.125052659994422388e-01,
         4.858210330291591605e-02, -6.902596153269104431e-03,
         6.682612642430500391e-03, -5.612247004554610057e-03,
         9.767795567660207592e-04, -9.773758942738038254e-04,
         5.638322117219018645e-03, -9.483806049779926932e-04,
         8.493873281881353637e-04, -2.941738570564985666e-01,
         -4.482529909499673171e-02, 4.091569840186781021e-02,
         -4.509020615859140463e-02, -1.013919988807244071e-01,
         1.551440772665269030e-01, 4.181857726606644232e-02,
         1.547200233064863484e-01, -2.398213304685777592e-01,
         -3.218625798524068354e-02, -1.012438450438508421e-02,
         1.271639330380921855e-02, 3.072814938490859779e-03,
         -9.556241797915024372e-02, 1.512251983492413077e-01,
         -8.277872384009607454e-03, 1.505412040827929787e-01,
         -2.386150620881526407e-01, -2.312295470054945568e-01,
         -6.631490213524345034e-02, 7.932427266386249398e-02,
         -8.053754366323923053e-02, -3.294595881137418747e-02,
         4.342495071150231922e-02, 1.004599500126941436e-01,
         4.450400364869536163e-02, -5.951077548033092968e-02
     ])
Ejemplo n.º 5
0
 def setUp(self):
     convert_pbtxt_to_pb(
         str(tests_path / os.path.join("infer", "deeppot-r.pbtxt")),
         "deeppot.pb")
     self.dp = DeepPot("deeppot.pb")
     self.coords = np.array([
         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.atype = [0, 1, 1, 0, 1, 1]
     self.box = np.array([13., 0., 0., 0., 13., 0., 0., 0., 13.])
     self.expected_e = np.array([
         -9.320909762801588272e+01, -1.868020345400987878e+02,
         -1.868011172371355997e+02, -9.320868430396934912e+01,
         -1.868010398844378415e+02, -1.868016706555875999e+02
     ])
     self.expected_f = np.array([
         6.385312846474267391e-04, -6.460452911141417731e-03,
         -5.652405655332678417e-04, -7.516468794343579736e-03,
         1.128804614240160216e-03, 5.531937784564192051e-03,
         1.914138124904981664e-03, 5.601819906021693503e-03,
         -5.131359585752605541e-03, -4.847104424804288617e-03,
         1.992071550328819614e-03, -4.028159855157302516e-03,
         1.236340684486603517e-03, -5.373955841338794344e-03,
         8.312829460571366513e-03, 8.574563125108854156e-03,
         3.111712681889538742e-03, -4.120007238692381148e-03
     ])
     self.expected_v = np.array([
         5.844056241889131371e-03, 4.663973497239899614e-04,
         -2.268382127762904633e-03, 4.663973497239897988e-04,
         2.349338784202595950e-03, -6.908546513234039253e-04,
         -2.268382127762904633e-03, -6.908546513234039253e-04,
         2.040499248150800561e-03, 4.238130266437327605e-03,
         -1.539867187443782223e-04, -2.393101333240631613e-03,
         -1.539867187443782223e-04, 4.410341945447907377e-04,
         9.544239698119633068e-06, -2.393101333240631613e-03,
         9.544239698119578858e-06, 1.877785959095269654e-03,
         5.798992562057291543e-03, 6.943392552230453693e-04,
         -1.180376879311998773e-03, 6.943392552230453693e-04,
         1.686725132156275536e-03, -1.461632060145726542e-03,
         -1.180376879311998556e-03, -1.461632060145726325e-03,
         1.749543733794208444e-03, 7.173915604192910439e-03,
         3.903218041111061569e-04, -5.747400467123527524e-04,
         3.903218041111061569e-04, 1.208289706621179949e-03,
         -1.826828914132010932e-03, -5.747400467123527524e-04,
         -1.826828914132011148e-03, 2.856960586657185906e-03,
         4.067553030177322240e-03, -3.267469855253819430e-05,
         -6.980667859103454904e-05, -3.267469855253830272e-05,
         1.387653029234650918e-03, -2.096820720698671855e-03,
         -6.980667859103444062e-05, -2.096820720698671855e-03,
         3.218305506720191278e-03, 4.753992590355240674e-03,
         1.224911338353675992e-03, -1.683421934571502484e-03,
         1.224911338353676209e-03, 7.332113564901583539e-04,
         -1.025577052190138451e-03, -1.683421934571502484e-03,
         -1.025577052190138234e-03, 1.456681925652047018e-03
     ])
class TestDeepPotAPBC(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        self.dp_original = DeepPot(FROZEN_MODEL)
        self.dp_compressed = DeepPot(COMPRESSED_MODEL)
        self.coords = np.array([
            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.atype = [0, 1, 1, 0, 1, 1]
        self.box = np.array([13., 0., 0., 0., 13., 0., 0., 0., 13.])

    def test_attrs(self):
        self.assertEqual(self.dp_original.get_ntypes(), 2)
        self.assertAlmostEqual(self.dp_original.get_rcut(),
                               6.0,
                               places=default_places)
        self.assertEqual(self.dp_original.get_type_map(), ['O', 'H'])
        self.assertEqual(self.dp_original.get_dim_fparam(), 0)
        self.assertEqual(self.dp_original.get_dim_aparam(), 0)

        self.assertEqual(self.dp_compressed.get_ntypes(), 2)
        self.assertAlmostEqual(self.dp_compressed.get_rcut(),
                               6.0,
                               places=default_places)
        self.assertEqual(self.dp_compressed.get_type_map(), ['O', 'H'])
        self.assertEqual(self.dp_compressed.get_dim_fparam(), 0)
        self.assertEqual(self.dp_compressed.get_dim_aparam(), 0)

    def test_1frame(self):
        ee0, ff0, vv0 = self.dp_original.eval(self.coords,
                                              self.box,
                                              self.atype,
                                              atomic=False)
        ee1, ff1, vv1 = self.dp_compressed.eval(self.coords,
                                                self.box,
                                                self.atype,
                                                atomic=False)
        # check shape of the returns
        nframes = 1
        natoms = len(self.atype)
        self.assertEqual(ee0.shape, (nframes, 1))
        self.assertEqual(ff0.shape, (nframes, natoms, 3))
        self.assertEqual(vv0.shape, (nframes, 9))
        self.assertEqual(ee1.shape, (nframes, 1))
        self.assertEqual(ff1.shape, (nframes, natoms, 3))
        self.assertEqual(vv1.shape, (nframes, 9))
        # check values
        np.testing.assert_almost_equal(ff0, ff1, default_places)
        np.testing.assert_almost_equal(ee0, ee1, default_places)
        np.testing.assert_almost_equal(vv0, vv1, default_places)

    def test_1frame_atm(self):
        ee0, ff0, vv0, ae0, av0 = self.dp_original.eval(self.coords,
                                                        self.box,
                                                        self.atype,
                                                        atomic=True)
        ee1, ff1, vv1, ae1, av1 = self.dp_compressed.eval(self.coords,
                                                          self.box,
                                                          self.atype,
                                                          atomic=True)
        # check shape of the returns
        nframes = 1
        natoms = len(self.atype)
        self.assertEqual(ee0.shape, (nframes, 1))
        self.assertEqual(ff0.shape, (nframes, natoms, 3))
        self.assertEqual(vv0.shape, (nframes, 9))
        self.assertEqual(ae0.shape, (nframes, natoms, 1))
        self.assertEqual(av0.shape, (nframes, natoms, 9))
        self.assertEqual(ee1.shape, (nframes, 1))
        self.assertEqual(ff1.shape, (nframes, natoms, 3))
        self.assertEqual(vv1.shape, (nframes, 9))
        self.assertEqual(ae1.shape, (nframes, natoms, 1))
        self.assertEqual(av1.shape, (nframes, natoms, 9))
        # check values
        np.testing.assert_almost_equal(ff0, ff1, default_places)
        np.testing.assert_almost_equal(ae0, ae1, default_places)
        np.testing.assert_almost_equal(av0, av1, default_places)
        np.testing.assert_almost_equal(ee0, ee1, default_places)
        np.testing.assert_almost_equal(vv0, vv1, default_places)

    def test_2frame_atm(self):
        coords2 = np.concatenate((self.coords, self.coords))
        box2 = np.concatenate((self.box, self.box))
        ee0, ff0, vv0, ae0, av0 = self.dp_original.eval(coords2,
                                                        box2,
                                                        self.atype,
                                                        atomic=True)
        ee1, ff1, vv1, ae1, av1 = self.dp_compressed.eval(coords2,
                                                          box2,
                                                          self.atype,
                                                          atomic=True)
        # check shape of the returns
        nframes = 2
        natoms = len(self.atype)
        self.assertEqual(ee0.shape, (nframes, 1))
        self.assertEqual(ff0.shape, (nframes, natoms, 3))
        self.assertEqual(vv0.shape, (nframes, 9))
        self.assertEqual(ae0.shape, (nframes, natoms, 1))
        self.assertEqual(av0.shape, (nframes, natoms, 9))
        self.assertEqual(ee1.shape, (nframes, 1))
        self.assertEqual(ff1.shape, (nframes, natoms, 3))
        self.assertEqual(vv1.shape, (nframes, 9))
        self.assertEqual(ae1.shape, (nframes, natoms, 1))
        self.assertEqual(av1.shape, (nframes, natoms, 9))

        # check values
        np.testing.assert_almost_equal(ff0, ff1, default_places)
        np.testing.assert_almost_equal(ae0, ae1, default_places)
        np.testing.assert_almost_equal(av0, av1, default_places)
        np.testing.assert_almost_equal(ee0, ee1, default_places)
        np.testing.assert_almost_equal(vv0, vv1, default_places)
class TestDeepPotAPBCExcludeTypes(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        self.dp_original = DeepPot(FROZEN_MODEL)
        self.dp_compressed = DeepPot(COMPRESSED_MODEL)
        self.coords = np.array([
            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.atype = [0, 1, 1, 0, 1, 1]
        self.box = np.array([13., 0., 0., 0., 13., 0., 0., 0., 13.])

    @classmethod
    def tearDownClass(self):
        _file_delete(INPUT)
        _file_delete(FROZEN_MODEL)
        _file_delete(COMPRESSED_MODEL)
        _file_delete("out.json")
        _file_delete("compress.json")
        _file_delete("checkpoint")
        _file_delete("model.ckpt.meta")
        _file_delete("model.ckpt.index")
        _file_delete("model.ckpt.data-00000-of-00001")
        _file_delete("model.ckpt-100.meta")
        _file_delete("model.ckpt-100.index")
        _file_delete("model.ckpt-100.data-00000-of-00001")
        _file_delete("model-compression/checkpoint")
        _file_delete("model-compression/model.ckpt.meta")
        _file_delete("model-compression/model.ckpt.index")
        _file_delete("model-compression/model.ckpt.data-00000-of-00001")
        _file_delete("model-compression")
        _file_delete("input_v2_compat.json")
        _file_delete("lcurve.out")

    def test_attrs(self):
        self.assertEqual(self.dp_original.get_ntypes(), 2)
        self.assertAlmostEqual(self.dp_original.get_rcut(),
                               6.0,
                               places=default_places)
        self.assertEqual(self.dp_original.get_type_map(), ['O', 'H'])
        self.assertEqual(self.dp_original.get_dim_fparam(), 0)
        self.assertEqual(self.dp_original.get_dim_aparam(), 0)

        self.assertEqual(self.dp_compressed.get_ntypes(), 2)
        self.assertAlmostEqual(self.dp_compressed.get_rcut(),
                               6.0,
                               places=default_places)
        self.assertEqual(self.dp_compressed.get_type_map(), ['O', 'H'])
        self.assertEqual(self.dp_compressed.get_dim_fparam(), 0)
        self.assertEqual(self.dp_compressed.get_dim_aparam(), 0)

    def test_1frame(self):
        ee0, ff0, vv0 = self.dp_original.eval(self.coords,
                                              self.box,
                                              self.atype,
                                              atomic=False)
        ee1, ff1, vv1 = self.dp_compressed.eval(self.coords,
                                                self.box,
                                                self.atype,
                                                atomic=False)
        # check shape of the returns
        nframes = 1
        natoms = len(self.atype)
        self.assertEqual(ee0.shape, (nframes, 1))
        self.assertEqual(ff0.shape, (nframes, natoms, 3))
        self.assertEqual(vv0.shape, (nframes, 9))
        self.assertEqual(ee1.shape, (nframes, 1))
        self.assertEqual(ff1.shape, (nframes, natoms, 3))
        self.assertEqual(vv1.shape, (nframes, 9))
        # check values
        np.testing.assert_almost_equal(ff0, ff1, default_places)
        np.testing.assert_almost_equal(ee0, ee1, default_places)
        np.testing.assert_almost_equal(vv0, vv1, default_places)

    def test_1frame_atm(self):
        ee0, ff0, vv0, ae0, av0 = self.dp_original.eval(self.coords,
                                                        self.box,
                                                        self.atype,
                                                        atomic=True)
        ee1, ff1, vv1, ae1, av1 = self.dp_compressed.eval(self.coords,
                                                          self.box,
                                                          self.atype,
                                                          atomic=True)
        # check shape of the returns
        nframes = 1
        natoms = len(self.atype)
        self.assertEqual(ee0.shape, (nframes, 1))
        self.assertEqual(ff0.shape, (nframes, natoms, 3))
        self.assertEqual(vv0.shape, (nframes, 9))
        self.assertEqual(ae0.shape, (nframes, natoms, 1))
        self.assertEqual(av0.shape, (nframes, natoms, 9))
        self.assertEqual(ee1.shape, (nframes, 1))
        self.assertEqual(ff1.shape, (nframes, natoms, 3))
        self.assertEqual(vv1.shape, (nframes, 9))
        self.assertEqual(ae1.shape, (nframes, natoms, 1))
        self.assertEqual(av1.shape, (nframes, natoms, 9))
        # check values
        np.testing.assert_almost_equal(ff0, ff1, default_places)
        np.testing.assert_almost_equal(ae0, ae1, default_places)
        np.testing.assert_almost_equal(av0, av1, default_places)
        np.testing.assert_almost_equal(ee0, ee1, default_places)
        np.testing.assert_almost_equal(vv0, vv1, default_places)

    def test_2frame_atm(self):
        coords2 = np.concatenate((self.coords, self.coords))
        box2 = np.concatenate((self.box, self.box))
        ee0, ff0, vv0, ae0, av0 = self.dp_original.eval(coords2,
                                                        box2,
                                                        self.atype,
                                                        atomic=True)
        ee1, ff1, vv1, ae1, av1 = self.dp_compressed.eval(coords2,
                                                          box2,
                                                          self.atype,
                                                          atomic=True)
        # check shape of the returns
        nframes = 2
        natoms = len(self.atype)
        self.assertEqual(ee0.shape, (nframes, 1))
        self.assertEqual(ff0.shape, (nframes, natoms, 3))
        self.assertEqual(vv0.shape, (nframes, 9))
        self.assertEqual(ae0.shape, (nframes, natoms, 1))
        self.assertEqual(av0.shape, (nframes, natoms, 9))
        self.assertEqual(ee1.shape, (nframes, 1))
        self.assertEqual(ff1.shape, (nframes, natoms, 3))
        self.assertEqual(vv1.shape, (nframes, 9))
        self.assertEqual(ae1.shape, (nframes, natoms, 1))
        self.assertEqual(av1.shape, (nframes, natoms, 9))

        # check values
        np.testing.assert_almost_equal(ff0, ff1, default_places)
        np.testing.assert_almost_equal(ae0, ae1, default_places)
        np.testing.assert_almost_equal(av0, av1, default_places)
        np.testing.assert_almost_equal(ee0, ee1, default_places)
        np.testing.assert_almost_equal(vv0, vv1, default_places)
class TestDeepPotALargeBoxNoPBC(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        self.dp_original = DeepPot(FROZEN_MODEL)
        self.dp_compressed = DeepPot(COMPRESSED_MODEL)
        self.coords = np.array([
            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.atype = [0, 1, 1, 0, 1, 1]
        self.box = np.array([19., 0., 0., 0., 13., 0., 0., 0., 13.])

    def test_1frame(self):
        ee0, ff0, vv0 = self.dp_original.eval(self.coords,
                                              self.box,
                                              self.atype,
                                              atomic=False)
        ee1, ff1, vv1 = self.dp_compressed.eval(self.coords,
                                                self.box,
                                                self.atype,
                                                atomic=False)
        # check shape of the returns
        nframes = 1
        natoms = len(self.atype)
        self.assertEqual(ee0.shape, (nframes, 1))
        self.assertEqual(ff0.shape, (nframes, natoms, 3))
        self.assertEqual(vv0.shape, (nframes, 9))
        self.assertEqual(ee1.shape, (nframes, 1))
        self.assertEqual(ff1.shape, (nframes, natoms, 3))
        self.assertEqual(vv1.shape, (nframes, 9))
        # check values
        np.testing.assert_almost_equal(ff0, ff1, default_places)
        np.testing.assert_almost_equal(ee0, ee1, default_places)
        np.testing.assert_almost_equal(vv0, vv1, default_places)

    def test_1frame_atm(self):
        ee0, ff0, vv0, ae0, av0 = self.dp_original.eval(self.coords,
                                                        self.box,
                                                        self.atype,
                                                        atomic=True)
        ee1, ff1, vv1, ae1, av1 = self.dp_compressed.eval(self.coords,
                                                          self.box,
                                                          self.atype,
                                                          atomic=True)
        # check shape of the returns
        nframes = 1
        natoms = len(self.atype)
        self.assertEqual(ee0.shape, (nframes, 1))
        self.assertEqual(ff0.shape, (nframes, natoms, 3))
        self.assertEqual(vv0.shape, (nframes, 9))
        self.assertEqual(ae0.shape, (nframes, natoms, 1))
        self.assertEqual(av0.shape, (nframes, natoms, 9))
        self.assertEqual(ee1.shape, (nframes, 1))
        self.assertEqual(ff1.shape, (nframes, natoms, 3))
        self.assertEqual(vv1.shape, (nframes, 9))
        self.assertEqual(ae1.shape, (nframes, natoms, 1))
        self.assertEqual(av1.shape, (nframes, natoms, 9))
        # check values
        np.testing.assert_almost_equal(ff0, ff1, default_places)
        np.testing.assert_almost_equal(ae0, ae1, default_places)
        np.testing.assert_almost_equal(av0, av1, default_places)
        np.testing.assert_almost_equal(ee0, ee1, default_places)
        np.testing.assert_almost_equal(vv0, vv1, default_places)

    def test_ase(self):
        from ase import Atoms
        from deepmd.calculator import DP
        water0 = Atoms('OHHOHH',
                       positions=self.coords.reshape((-1, 3)),
                       cell=self.box.reshape((3, 3)),
                       calculator=DP(FROZEN_MODEL))
        water1 = Atoms('OHHOHH',
                       positions=self.coords.reshape((-1, 3)),
                       cell=self.box.reshape((3, 3)),
                       calculator=DP(COMPRESSED_MODEL))
        ee0 = water0.get_potential_energy()
        ff0 = water0.get_forces()
        ee1 = water1.get_potential_energy()
        ff1 = water1.get_forces()
        nframes = 1
        np.testing.assert_almost_equal(ff0, ff1, default_places)
        np.testing.assert_almost_equal(ee0, ee1, default_places)
Ejemplo n.º 9
0
class TestDeepPotAPBC(unittest.TestCase):
    def setUp(self):
        convert_pbtxt_to_pb(
            str(tests_path / os.path.join("infer", "deeppot.pbtxt")),
            "deeppot.pb")
        self.dp = DeepPot("deeppot.pb")
        self.coords = np.array([
            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.atype = [0, 1, 1, 0, 1, 1]
        self.box = np.array([13., 0., 0., 0., 13., 0., 0., 0., 13.])
        self.expected_e = np.array([
            -9.275780747115504710e+01, -1.863501786584258468e+02,
            -1.863392472863538103e+02, -9.279281325486221021e+01,
            -1.863671545232153903e+02, -1.863619822847602165e+02
        ])
        self.expected_f = np.array([
            -3.034045420701179663e-01, 8.405844663871177014e-01,
            7.696947487118485642e-02, 7.662001266663505117e-01,
            -1.880601391333554251e-01, -6.183333871091722944e-01,
            -5.036172391059643427e-01, -6.529525836149027151e-01,
            5.432962643022043459e-01, 6.382357912332115024e-01,
            -1.748518296794561167e-01, 3.457363524891907125e-01,
            1.286482986991941552e-03, 3.757251165286925043e-01,
            -5.972588700887541124e-01, -5.987006197104716154e-01,
            -2.004450304880958100e-01, 2.495901655353461868e-01
        ])
        self.expected_v = np.array([
            -2.912234126853306959e-01, -3.800610846612756388e-02,
            2.776624987489437202e-01, -5.053761003913598976e-02,
            -3.152373041953385746e-01, 1.060894290092162379e-01,
            2.826389131596073745e-01, 1.039129970665329250e-01,
            -2.584378792325942586e-01, -3.121722367954994914e-01,
            8.483275876786681990e-02, 2.524662342344257682e-01,
            4.142176771106586414e-02, -3.820285230785245428e-02,
            -2.727311173065460545e-02, 2.668859789777112135e-01,
            -6.448243569420382404e-02, -2.121731470426218846e-01,
            -8.624335220278558922e-02, -1.809695356746038597e-01,
            1.529875294531883312e-01, -1.283658185172031341e-01,
            -1.992682279795223999e-01, 1.409924999632362341e-01,
            1.398322735274434292e-01, 1.804318474574856390e-01,
            -1.470309318999652726e-01, -2.593983661598450730e-01,
            -4.236536279233147489e-02, 3.386387920184946720e-02,
            -4.174017537818433543e-02, -1.003500282164128260e-01,
            1.525690815194478966e-01, 3.398976109910181037e-02,
            1.522253908435125536e-01, -2.349125581341701963e-01,
            9.515545977581392825e-04, -1.643218849228543846e-02,
            1.993234765412972564e-02, 6.027265332209678569e-04,
            -9.563256398907417355e-02, 1.510815124001868293e-01,
            -7.738094816888557714e-03, 1.502832772532304295e-01,
            -2.380965783745832010e-01, -2.309456719810296654e-01,
            -6.666961081213038098e-02, 7.955566551234216632e-02,
            -8.099093777937517447e-02, -3.386641099800401927e-02,
            4.447884755740908608e-02, 1.008593228579038742e-01,
            4.556718179228393811e-02, -6.078081273849572641e-02
        ])

    def tearDown(self):
        os.remove("deeppot.pb")

    def test_attrs(self):
        self.assertEqual(self.dp.get_ntypes(), 2)
        self.assertAlmostEqual(self.dp.get_rcut(), 6.0, places=default_places)
        self.assertEqual(self.dp.get_type_map(), ['O', 'H'])
        self.assertEqual(self.dp.get_dim_fparam(), 0)
        self.assertEqual(self.dp.get_dim_aparam(), 0)

    def test_1frame(self):
        ee, ff, vv = self.dp.eval(self.coords,
                                  self.box,
                                  self.atype,
                                  atomic=False)
        # check shape of the returns
        nframes = 1
        natoms = len(self.atype)
        self.assertEqual(ee.shape, (nframes, 1))
        self.assertEqual(ff.shape, (nframes, natoms, 3))
        self.assertEqual(vv.shape, (nframes, 9))
        # check values
        np.testing.assert_almost_equal(ff.ravel(), self.expected_f.ravel(),
                                       default_places)
        expected_se = np.sum(self.expected_e.reshape([nframes, -1]), axis=1)
        np.testing.assert_almost_equal(ee.ravel(), expected_se.ravel(),
                                       default_places)
        expected_sv = np.sum(self.expected_v.reshape([nframes, -1, 9]), axis=1)
        np.testing.assert_almost_equal(vv.ravel(), expected_sv.ravel(),
                                       default_places)

    def test_1frame_atm(self):
        ee, ff, vv, ae, av = self.dp.eval(self.coords,
                                          self.box,
                                          self.atype,
                                          atomic=True)
        # check shape of the returns
        nframes = 1
        natoms = len(self.atype)
        self.assertEqual(ee.shape, (nframes, 1))
        self.assertEqual(ff.shape, (nframes, natoms, 3))
        self.assertEqual(vv.shape, (nframes, 9))
        self.assertEqual(ae.shape, (nframes, natoms, 1))
        self.assertEqual(av.shape, (nframes, natoms, 9))
        # check values
        np.testing.assert_almost_equal(ff.ravel(), self.expected_f.ravel(),
                                       default_places)
        np.testing.assert_almost_equal(ae.ravel(), self.expected_e.ravel(),
                                       default_places)
        np.testing.assert_almost_equal(av.ravel(), self.expected_v.ravel(),
                                       default_places)
        expected_se = np.sum(self.expected_e.reshape([nframes, -1]), axis=1)
        np.testing.assert_almost_equal(ee.ravel(), expected_se.ravel(),
                                       default_places)
        expected_sv = np.sum(self.expected_v.reshape([nframes, -1, 9]), axis=1)
        np.testing.assert_almost_equal(vv.ravel(), expected_sv.ravel(),
                                       default_places)

    def test_2frame_atm(self):
        coords2 = np.concatenate((self.coords, self.coords))
        box2 = np.concatenate((self.box, self.box))
        ee, ff, vv, ae, av = self.dp.eval(coords2,
                                          box2,
                                          self.atype,
                                          atomic=True)
        # check shape of the returns
        nframes = 2
        natoms = len(self.atype)
        self.assertEqual(ee.shape, (nframes, 1))
        self.assertEqual(ff.shape, (nframes, natoms, 3))
        self.assertEqual(vv.shape, (nframes, 9))
        self.assertEqual(ae.shape, (nframes, natoms, 1))
        self.assertEqual(av.shape, (nframes, natoms, 9))
        # check values
        expected_f = np.concatenate((self.expected_f, self.expected_f), axis=0)
        expected_e = np.concatenate((self.expected_e, self.expected_e), axis=0)
        expected_v = np.concatenate((self.expected_v, self.expected_v), axis=0)
        np.testing.assert_almost_equal(ff.ravel(), expected_f.ravel(),
                                       default_places)
        np.testing.assert_almost_equal(ae.ravel(), expected_e.ravel(),
                                       default_places)
        np.testing.assert_almost_equal(av.ravel(), expected_v.ravel(),
                                       default_places)
        expected_se = np.sum(expected_e.reshape([nframes, -1]), axis=1)
        np.testing.assert_almost_equal(ee.ravel(), expected_se.ravel(),
                                       default_places)
        expected_sv = np.sum(expected_v.reshape([nframes, -1, 9]), axis=1)
        np.testing.assert_almost_equal(vv.ravel(), expected_sv.ravel(),
                                       default_places)
Ejemplo n.º 10
0
 def test(self):
     with self.assertRaises(RuntimeError) as context:
         DeepPot(self.version_pb)
     self.assertTrue('incompatible' in str(context.exception))
     self.assertTrue(MODEL_VERSION in str(context.exception))
     self.assertTrue('0.1000000' in str(context.exception))
Ejemplo n.º 11
0
class TestDeepPotALargeBoxNoPBC(unittest.TestCase):
    def setUp(self):
        convert_pbtxt_to_pb(
            str(tests_path / os.path.join("infer", "deeppot.pbtxt")),
            "deeppot.pb")
        self.dp = DeepPot("deeppot.pb")
        self.coords = np.array([
            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.atype = [0, 1, 1, 0, 1, 1]
        self.box = np.array([19., 0., 0., 0., 13., 0., 0., 0., 13.])
        self.expected_e = np.array([
            -9.255934839310273787e+01, -1.863253376736990106e+02,
            -1.857237299341402945e+02, -9.279308539717486326e+01,
            -1.863708105823244239e+02, -1.863635196514972563e+02
        ])
        self.expected_f = np.array([
            -2.161037360255332107e+00, 9.052994347015581589e-01,
            1.635379623977007979e+00, 2.161037360255332107e+00,
            -9.052994347015581589e-01, -1.635379623977007979e+00,
            -1.167128117249453811e-02, 1.371975700096064992e-03,
            -1.575265180249604477e-03, 6.226508593971802341e-01,
            -1.816734122009256991e-01, 3.561766019664774907e-01,
            -1.406075393906316626e-02, 3.789140061530929526e-01,
            -6.018777878642909140e-01, -5.969188242856223736e-01,
            -1.986125696522633155e-01, 2.472764510780630642e-01
        ])
        self.expected_v = np.array([
            -7.042445481792056761e-01, 2.950213647777754078e-01,
            5.329418202437231633e-01, 2.950213647777752968e-01,
            -1.235900311906896754e-01, -2.232594111831812944e-01,
            5.329418202437232743e-01, -2.232594111831813499e-01,
            -4.033073234276823849e-01, -8.949230984097404917e-01,
            3.749002169013777030e-01, 6.772391014992630298e-01,
            3.749002169013777586e-01, -1.570527935667933583e-01,
            -2.837082722496912512e-01, 6.772391014992631408e-01,
            -2.837082722496912512e-01, -5.125052659994422388e-01,
            4.858210330291591605e-02, -6.902596153269104431e-03,
            6.682612642430500391e-03, -5.612247004554610057e-03,
            9.767795567660207592e-04, -9.773758942738038254e-04,
            5.638322117219018645e-03, -9.483806049779926932e-04,
            8.493873281881353637e-04, -2.941738570564985666e-01,
            -4.482529909499673171e-02, 4.091569840186781021e-02,
            -4.509020615859140463e-02, -1.013919988807244071e-01,
            1.551440772665269030e-01, 4.181857726606644232e-02,
            1.547200233064863484e-01, -2.398213304685777592e-01,
            -3.218625798524068354e-02, -1.012438450438508421e-02,
            1.271639330380921855e-02, 3.072814938490859779e-03,
            -9.556241797915024372e-02, 1.512251983492413077e-01,
            -8.277872384009607454e-03, 1.505412040827929787e-01,
            -2.386150620881526407e-01, -2.312295470054945568e-01,
            -6.631490213524345034e-02, 7.932427266386249398e-02,
            -8.053754366323923053e-02, -3.294595881137418747e-02,
            4.342495071150231922e-02, 1.004599500126941436e-01,
            4.450400364869536163e-02, -5.951077548033092968e-02
        ])

    def tearDown(self):
        os.remove("deeppot.pb")

    def test_1frame(self):
        ee, ff, vv = self.dp.eval(self.coords,
                                  self.box,
                                  self.atype,
                                  atomic=False)
        # check shape of the returns
        nframes = 1
        natoms = len(self.atype)
        self.assertEqual(ee.shape, (nframes, 1))
        self.assertEqual(ff.shape, (nframes, natoms, 3))
        self.assertEqual(vv.shape, (nframes, 9))
        # check values
        np.testing.assert_almost_equal(ff.ravel(), self.expected_f.ravel(),
                                       default_places)
        expected_se = np.sum(self.expected_e.reshape([nframes, -1]), axis=1)
        np.testing.assert_almost_equal(ee.ravel(), expected_se.ravel(),
                                       default_places)
        expected_sv = np.sum(self.expected_v.reshape([nframes, -1, 9]), axis=1)
        np.testing.assert_almost_equal(vv.ravel(), expected_sv.ravel(),
                                       default_places)

    def test_1frame_atm(self):
        ee, ff, vv, ae, av = self.dp.eval(self.coords,
                                          self.box,
                                          self.atype,
                                          atomic=True)
        # check shape of the returns
        nframes = 1
        natoms = len(self.atype)
        self.assertEqual(ee.shape, (nframes, 1))
        self.assertEqual(ff.shape, (nframes, natoms, 3))
        self.assertEqual(vv.shape, (nframes, 9))
        self.assertEqual(ae.shape, (nframes, natoms, 1))
        self.assertEqual(av.shape, (nframes, natoms, 9))
        # check values
        np.testing.assert_almost_equal(ff.ravel(), self.expected_f.ravel(),
                                       default_places)
        np.testing.assert_almost_equal(ae.ravel(), self.expected_e.ravel(),
                                       default_places)
        np.testing.assert_almost_equal(av.ravel(), self.expected_v.ravel(),
                                       default_places)
        expected_se = np.sum(self.expected_e.reshape([nframes, -1]), axis=1)
        np.testing.assert_almost_equal(ee.ravel(), expected_se.ravel(),
                                       default_places)
        expected_sv = np.sum(self.expected_v.reshape([nframes, -1, 9]), axis=1)
        np.testing.assert_almost_equal(vv.ravel(), expected_sv.ravel(),
                                       default_places)

    def test_ase(self):
        from ase import Atoms
        from deepmd.calculator import DP
        water = Atoms('OHHOHH',
                      positions=self.coords.reshape((-1, 3)),
                      cell=self.box.reshape((3, 3)),
                      calculator=DP("deeppot.pb"))
        ee = water.get_potential_energy()
        ff = water.get_forces()
        nframes = 1
        np.testing.assert_almost_equal(ff.ravel(), self.expected_f.ravel(),
                                       default_places)
        expected_se = np.sum(self.expected_e.reshape([nframes, -1]), axis=1)
        np.testing.assert_almost_equal(ee.ravel(), expected_se.ravel(),
                                       default_places)
Ejemplo n.º 12
0
 def setUpClass(cls):
     convert_pbtxt_to_pb(
         str(tests_path / os.path.join("infer", "deeppot.pbtxt")),
         "deeppot.pb")
     cls.dp = DeepPot("deeppot.pb")
Ejemplo n.º 13
0
class TestDeepPotRLargeBoxNoPBC(unittest.TestCase):
    def setUp(self):
        convert_pbtxt_to_pb(
            str(tests_path / os.path.join("infer", "deeppot-r.pbtxt")),
            "deeppot.pb")
        self.dp = DeepPot("deeppot.pb")
        self.coords = np.array([
            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.atype = [0, 1, 1, 0, 1, 1]
        self.box = np.array([19., 0., 0., 0., 13., 0., 0., 0., 13.])
        self.expected_e = np.array([
            -9.321213823508108476e+01, -1.868044102481340758e+02,
            -1.868067983858651075e+02, -9.320899631301440991e+01,
            -1.868014559732615112e+02, -1.868017660713088617e+02
        ])
        self.expected_f = np.array([
            4.578151103701261042e-03, -1.917874111009987628e-03,
            -3.464546781179331930e-03, -4.578151103701261042e-03,
            1.917874111009987628e-03, 3.464546781179331930e-03,
            -2.624402581721222913e-03, 3.566275128489623933e-04,
            -2.859315986763691776e-04, -5.767787273464367384e-03,
            1.907053583551196647e-03, -3.889064429673861831e-03,
            1.786820066350549132e-04, -5.327197473636275694e-03,
            8.236236182834734409e-03, 8.213507848550535492e-03,
            3.063516377236116545e-03, -4.061240154484504865e-03
        ])
        self.expected_v = np.array([
            1.984979026299632174e-03, -8.315452677741701822e-04,
            -1.502146290172694243e-03, -8.315452677741700738e-04,
            3.483500446080982317e-04, 6.292774999372096039e-04,
            -1.502146290172694243e-03, 6.292774999372097123e-04,
            1.136759354725281907e-03, 1.402852790439301908e-03,
            -5.876815743732210226e-04, -1.061618327900012114e-03,
            -5.876815743732211311e-04, 2.461909298049979960e-04,
            4.447320022283834766e-04, -1.061618327900012331e-03,
            4.447320022283834766e-04, 8.033868427351443728e-04,
            4.143606961846296385e-03, -5.511382161123719835e-04,
            4.465413399437045397e-04, -5.511382161123719835e-04,
            1.082271054025323839e-04, -1.097918001262628728e-04,
            4.465413399437046481e-04, -1.097918001262628728e-04,
            1.220966982358671871e-04, 5.263952004497593831e-03,
            2.395243710938091842e-04, -2.830378939414603329e-04,
            2.395243710938094010e-04, 1.189969706598244898e-03,
            -1.805627331015851201e-03, -2.830378939414602245e-04,
            -1.805627331015851635e-03, 2.801996513751836820e-03,
            2.208413501170402270e-03, 5.331756287635716889e-05,
            -1.664423506603235218e-04, 5.331756287635695205e-05,
            1.379626072862918072e-03, -2.094132943741625064e-03,
            -1.664423506603234133e-04, -2.094132943741625064e-03,
            3.199787996743366607e-03, 4.047014004814953811e-03,
            1.137904999421357000e-03, -1.568106936614101698e-03,
            1.137904999421357217e-03, 7.205982843216952307e-04,
            -1.011174600268313238e-03, -1.568106936614101698e-03,
            -1.011174600268313238e-03, 1.435226522157425754e-03
        ])

    def tearDown(self):
        os.remove("deeppot.pb")

    def test_1frame(self):
        ee, ff, vv = self.dp.eval(self.coords,
                                  self.box,
                                  self.atype,
                                  atomic=False)
        # check shape of the returns
        nframes = 1
        natoms = len(self.atype)
        self.assertEqual(ee.shape, (nframes, 1))
        self.assertEqual(ff.shape, (nframes, natoms, 3))
        self.assertEqual(vv.shape, (nframes, 9))
        # check values
        np.testing.assert_almost_equal(ff.ravel(), self.expected_f.ravel(),
                                       default_places)
        expected_se = np.sum(self.expected_e.reshape([nframes, -1]), axis=1)
        np.testing.assert_almost_equal(ee.ravel(), expected_se.ravel(),
                                       default_places)
        expected_sv = np.sum(self.expected_v.reshape([nframes, -1, 9]), axis=1)
        np.testing.assert_almost_equal(vv.ravel(), expected_sv.ravel(),
                                       default_places)

    def test_1frame_atm(self):
        ee, ff, vv, ae, av = self.dp.eval(self.coords,
                                          self.box,
                                          self.atype,
                                          atomic=True)
        # check shape of the returns
        nframes = 1
        natoms = len(self.atype)
        self.assertEqual(ee.shape, (nframes, 1))
        self.assertEqual(ff.shape, (nframes, natoms, 3))
        self.assertEqual(vv.shape, (nframes, 9))
        self.assertEqual(ae.shape, (nframes, natoms, 1))
        self.assertEqual(av.shape, (nframes, natoms, 9))
        # check values
        np.testing.assert_almost_equal(ff.ravel(), self.expected_f.ravel(),
                                       default_places)
        np.testing.assert_almost_equal(ae.ravel(), self.expected_e.ravel(),
                                       default_places)
        np.testing.assert_almost_equal(av.ravel(), self.expected_v.ravel(),
                                       default_places)
        expected_se = np.sum(self.expected_e.reshape([nframes, -1]), axis=1)
        np.testing.assert_almost_equal(ee.ravel(), expected_se.ravel(),
                                       default_places)
        expected_sv = np.sum(self.expected_v.reshape([nframes, -1, 9]), axis=1)
        np.testing.assert_almost_equal(vv.ravel(), expected_sv.ravel(),
                                       default_places)
Ejemplo n.º 14
0
class TestDeepPotRPBC(unittest.TestCase):
    def setUp(self):
        convert_pbtxt_to_pb(
            str(tests_path / os.path.join("infer", "deeppot-r.pbtxt")),
            "deeppot.pb")
        self.dp = DeepPot("deeppot.pb")
        self.coords = np.array([
            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.atype = [0, 1, 1, 0, 1, 1]
        self.box = np.array([13., 0., 0., 0., 13., 0., 0., 0., 13.])
        self.expected_e = np.array([
            -9.320909762801588272e+01, -1.868020345400987878e+02,
            -1.868011172371355997e+02, -9.320868430396934912e+01,
            -1.868010398844378415e+02, -1.868016706555875999e+02
        ])
        self.expected_f = np.array([
            6.385312846474267391e-04, -6.460452911141417731e-03,
            -5.652405655332678417e-04, -7.516468794343579736e-03,
            1.128804614240160216e-03, 5.531937784564192051e-03,
            1.914138124904981664e-03, 5.601819906021693503e-03,
            -5.131359585752605541e-03, -4.847104424804288617e-03,
            1.992071550328819614e-03, -4.028159855157302516e-03,
            1.236340684486603517e-03, -5.373955841338794344e-03,
            8.312829460571366513e-03, 8.574563125108854156e-03,
            3.111712681889538742e-03, -4.120007238692381148e-03
        ])
        self.expected_v = np.array([
            5.844056241889131371e-03, 4.663973497239899614e-04,
            -2.268382127762904633e-03, 4.663973497239897988e-04,
            2.349338784202595950e-03, -6.908546513234039253e-04,
            -2.268382127762904633e-03, -6.908546513234039253e-04,
            2.040499248150800561e-03, 4.238130266437327605e-03,
            -1.539867187443782223e-04, -2.393101333240631613e-03,
            -1.539867187443782223e-04, 4.410341945447907377e-04,
            9.544239698119633068e-06, -2.393101333240631613e-03,
            9.544239698119578858e-06, 1.877785959095269654e-03,
            5.798992562057291543e-03, 6.943392552230453693e-04,
            -1.180376879311998773e-03, 6.943392552230453693e-04,
            1.686725132156275536e-03, -1.461632060145726542e-03,
            -1.180376879311998556e-03, -1.461632060145726325e-03,
            1.749543733794208444e-03, 7.173915604192910439e-03,
            3.903218041111061569e-04, -5.747400467123527524e-04,
            3.903218041111061569e-04, 1.208289706621179949e-03,
            -1.826828914132010932e-03, -5.747400467123527524e-04,
            -1.826828914132011148e-03, 2.856960586657185906e-03,
            4.067553030177322240e-03, -3.267469855253819430e-05,
            -6.980667859103454904e-05, -3.267469855253830272e-05,
            1.387653029234650918e-03, -2.096820720698671855e-03,
            -6.980667859103444062e-05, -2.096820720698671855e-03,
            3.218305506720191278e-03, 4.753992590355240674e-03,
            1.224911338353675992e-03, -1.683421934571502484e-03,
            1.224911338353676209e-03, 7.332113564901583539e-04,
            -1.025577052190138451e-03, -1.683421934571502484e-03,
            -1.025577052190138234e-03, 1.456681925652047018e-03
        ])

    def tearDown(self):
        os.remove("deeppot.pb")

    def test_attrs(self):
        self.assertEqual(self.dp.get_ntypes(), 2)
        self.assertAlmostEqual(self.dp.get_rcut(), 6.0, places=default_places)
        self.assertEqual(self.dp.get_type_map(), ['O', 'H'])
        self.assertEqual(self.dp.get_dim_fparam(), 0)
        self.assertEqual(self.dp.get_dim_aparam(), 0)

    # def test_1frame(self):
    #     ee, ff, vv, ae, av = self.dp.eval(self.coords, self.box, self.atype, atomic = True)
    #     np.savetxt('ee.out', ae.reshape([1, -1]), delimiter=',')
    #     np.savetxt('ff.out', ff.reshape([1, -1]), delimiter=',')
    #     np.savetxt('vv.out', av.reshape([1, -1]), delimiter=',')

    def test_1frame(self):
        ee, ff, vv = self.dp.eval(self.coords,
                                  self.box,
                                  self.atype,
                                  atomic=False)
        # check shape of the returns
        nframes = 1
        natoms = len(self.atype)
        self.assertEqual(ee.shape, (nframes, 1))
        self.assertEqual(ff.shape, (nframes, natoms, 3))
        self.assertEqual(vv.shape, (nframes, 9))
        # check values
        np.testing.assert_almost_equal(ff.ravel(), self.expected_f.ravel(),
                                       default_places)
        expected_se = np.sum(self.expected_e.reshape([nframes, -1]), axis=1)
        np.testing.assert_almost_equal(ee.ravel(), expected_se.ravel(),
                                       default_places)
        expected_sv = np.sum(self.expected_v.reshape([nframes, -1, 9]), axis=1)
        np.testing.assert_almost_equal(vv.ravel(), expected_sv.ravel(),
                                       default_places)

    def test_1frame_atm(self):
        ee, ff, vv, ae, av = self.dp.eval(self.coords,
                                          self.box,
                                          self.atype,
                                          atomic=True)
        # check shape of the returns
        nframes = 1
        natoms = len(self.atype)
        self.assertEqual(ee.shape, (nframes, 1))
        self.assertEqual(ff.shape, (nframes, natoms, 3))
        self.assertEqual(vv.shape, (nframes, 9))
        self.assertEqual(ae.shape, (nframes, natoms, 1))
        self.assertEqual(av.shape, (nframes, natoms, 9))
        # check values
        np.testing.assert_almost_equal(ff.ravel(), self.expected_f.ravel(),
                                       default_places)
        np.testing.assert_almost_equal(ae.ravel(), self.expected_e.ravel(),
                                       default_places)
        np.testing.assert_almost_equal(av.ravel(), self.expected_v.ravel(),
                                       default_places)
        expected_se = np.sum(self.expected_e.reshape([nframes, -1]), axis=1)
        np.testing.assert_almost_equal(ee.ravel(), expected_se.ravel(),
                                       default_places)
        expected_sv = np.sum(self.expected_v.reshape([nframes, -1, 9]), axis=1)
        np.testing.assert_almost_equal(vv.ravel(), expected_sv.ravel(),
                                       default_places)

    def test_2frame_atm(self):
        coords2 = np.concatenate((self.coords, self.coords))
        box2 = np.concatenate((self.box, self.box))
        ee, ff, vv, ae, av = self.dp.eval(coords2,
                                          box2,
                                          self.atype,
                                          atomic=True)
        # check shape of the returns
        nframes = 2
        natoms = len(self.atype)
        self.assertEqual(ee.shape, (nframes, 1))
        self.assertEqual(ff.shape, (nframes, natoms, 3))
        self.assertEqual(vv.shape, (nframes, 9))
        self.assertEqual(ae.shape, (nframes, natoms, 1))
        self.assertEqual(av.shape, (nframes, natoms, 9))
        # check values
        expected_f = np.concatenate((self.expected_f, self.expected_f), axis=0)
        expected_e = np.concatenate((self.expected_e, self.expected_e), axis=0)
        expected_v = np.concatenate((self.expected_v, self.expected_v), axis=0)
        np.testing.assert_almost_equal(ff.ravel(), expected_f.ravel(),
                                       default_places)
        np.testing.assert_almost_equal(ae.ravel(), expected_e.ravel(),
                                       default_places)
        np.testing.assert_almost_equal(av.ravel(), expected_v.ravel(),
                                       default_places)
        expected_se = np.sum(expected_e.reshape([nframes, -1]), axis=1)
        np.testing.assert_almost_equal(ee.ravel(), expected_se.ravel(),
                                       default_places)
        expected_sv = np.sum(expected_v.reshape([nframes, -1, 9]), axis=1)
        np.testing.assert_almost_equal(vv.ravel(), expected_sv.ravel(),
                                       default_places)