@@ -19,6 +19,10 @@ class TestInferDeepPotAPtExpt : public ::testing::Test {
1919 std::vector<VALUETYPE> coord = {12.83 , 2.56 , 2.18 , 12.09 , 2.87 , 2.74 ,
2020 00.25 , 3.32 , 1.68 , 3.36 , 3.00 , 1.81 ,
2121 3.51 , 2.51 , 2.60 , 4.27 , 3.22 , 1.56 };
22+ // Alternative coords for multi-frame tests (must give different energy)
23+ std::vector<VALUETYPE> coord_alt = {10.06 , 5.71 , 11.16 , 9.07 , 1.22 , 12.68 ,
24+ 9.89 , 10.22 , 1.67 , 5.86 , 4.82 , 12.05 ,
25+ 8.37 , 10.70 , 5.76 , 2.95 , 7.21 , 0.83 };
2226 std::vector<int > atype = {0 , 1 , 1 , 0 , 1 , 1 };
2327 std::vector<VALUETYPE> box = {13 ., 0 ., 0 ., 0 ., 13 ., 0 ., 0 ., 0 ., 13 .};
2428 // Same reference values as test_deeppot_pt.cc (model converted from .pth)
@@ -414,6 +418,9 @@ class TestInferDeepPotAPtExptNoPbc : public ::testing::Test {
414418 std::vector<VALUETYPE> coord = {12.83 , 2.56 , 2.18 , 12.09 , 2.87 , 2.74 ,
415419 00.25 , 3.32 , 1.68 , 3.36 , 3.00 , 1.81 ,
416420 3.51 , 2.51 , 2.60 , 4.27 , 3.22 , 1.56 };
421+ std::vector<VALUETYPE> coord_alt = {10.06 , 5.71 , 11.16 , 9.07 , 1.22 , 12.68 ,
422+ 9.89 , 10.22 , 1.67 , 5.86 , 4.82 , 12.05 ,
423+ 8.37 , 10.70 , 5.76 , 2.95 , 7.21 , 0.83 };
417424 std::vector<int > atype = {0 , 1 , 1 , 0 , 1 , 1 };
418425 std::vector<VALUETYPE> box = {};
419426 // Same reference values as TestInferDeepPotAPtNoPbc in test_deeppot_pt.cc
@@ -541,6 +548,7 @@ TYPED_TEST(TestInferDeepPotAPtExptNoPbc, cpu_build_nlist_atomic) {
541548TYPED_TEST (TestInferDeepPotAPtExpt, cpu_build_nlist_nframes) {
542549 using VALUETYPE = TypeParam;
543550 std::vector<VALUETYPE>& coord = this ->coord ;
551+ std::vector<VALUETYPE>& coord_alt = this ->coord_alt ;
544552 std::vector<int >& atype = this ->atype ;
545553 std::vector<VALUETYPE>& box = this ->box ;
546554 std::vector<VALUETYPE>& expected_f = this ->expected_f ;
@@ -550,8 +558,9 @@ TYPED_TEST(TestInferDeepPotAPtExpt, cpu_build_nlist_nframes) {
550558 deepmd::DeepPot& dp = this ->dp ;
551559
552560 int nframes = 2 ;
561+ // Frame 0: original coords. Frame 1: alternative coords (coord_alt).
553562 std::vector<VALUETYPE> coord_2f (coord);
554- coord_2f.insert (coord_2f.end (), coord .begin (), coord .end ());
563+ coord_2f.insert (coord_2f.end (), coord_alt .begin (), coord_alt .end ());
555564 std::vector<int > atype_2f (atype);
556565 atype_2f.insert (atype_2f.end (), atype.begin (), atype.end ());
557566 std::vector<VALUETYPE> box_2f (box);
@@ -566,22 +575,21 @@ TYPED_TEST(TestInferDeepPotAPtExpt, cpu_build_nlist_nframes) {
566575 EXPECT_EQ (force.size (), nframes * natoms * 3 );
567576 EXPECT_EQ (virial.size (), nframes * 9 );
568577
569- for (int ff = 0 ; ff < nframes; ++ff) {
570- EXPECT_LT (fabs (ener[ff] - expected_tot_e), EPSILON);
571- for (int ii = 0 ; ii < natoms * 3 ; ++ii) {
572- EXPECT_LT (fabs (force[ff * natoms * 3 + ii] - expected_f[ii]), EPSILON);
573- }
574- for (int ii = 0 ; ii < 9 ; ++ii) {
575- EXPECT_LT (fabs (virial[ff * 9 + ii] - expected_tot_v[ii]), EPSILON);
576- }
578+ // Frame 0 should match reference
579+ EXPECT_LT (fabs (ener[0 ] - expected_tot_e), EPSILON);
580+ for (int ii = 0 ; ii < natoms * 3 ; ++ii) {
581+ EXPECT_LT (fabs (force[ii] - expected_f[ii]), EPSILON);
577582 }
583+ // Frame 1 should be different (perturbed coords)
584+ EXPECT_GT (fabs (ener[1 ] - ener[0 ]), 1e-10 );
578585}
579586
580587// Multi-frame NoPBC test via compute_mixed_type
581588TYPED_TEST (TestInferDeepPotAPtExptNoPbc, cpu_build_nlist_nframes) {
582589 using VALUETYPE = TypeParam;
583590 std::vector<VALUETYPE>& coord = this ->coord ;
584591 std::vector<int >& atype = this ->atype ;
592+ std::vector<VALUETYPE>& coord_alt = this ->coord_alt ;
585593 std::vector<VALUETYPE>& box = this ->box ; // empty
586594 std::vector<VALUETYPE>& expected_f = this ->expected_f ;
587595 int & natoms = this ->natoms ;
@@ -591,7 +599,7 @@ TYPED_TEST(TestInferDeepPotAPtExptNoPbc, cpu_build_nlist_nframes) {
591599
592600 int nframes = 2 ;
593601 std::vector<VALUETYPE> coord_2f (coord);
594- coord_2f.insert (coord_2f.end (), coord .begin (), coord .end ());
602+ coord_2f.insert (coord_2f.end (), coord_alt .begin (), coord_alt .end ());
595603 std::vector<int > atype_2f (atype);
596604 atype_2f.insert (atype_2f.end (), atype.begin (), atype.end ());
597605
@@ -603,15 +611,13 @@ TYPED_TEST(TestInferDeepPotAPtExptNoPbc, cpu_build_nlist_nframes) {
603611 EXPECT_EQ (force.size (), nframes * natoms * 3 );
604612 EXPECT_EQ (virial.size (), nframes * 9 );
605613
606- for (int ff = 0 ; ff < nframes; ++ff) {
607- EXPECT_LT (fabs (ener[ff] - expected_tot_e), EPSILON);
608- for (int ii = 0 ; ii < natoms * 3 ; ++ii) {
609- EXPECT_LT (fabs (force[ff * natoms * 3 + ii] - expected_f[ii]), EPSILON);
610- }
611- for (int ii = 0 ; ii < 9 ; ++ii) {
612- EXPECT_LT (fabs (virial[ff * 9 + ii] - expected_tot_v[ii]), EPSILON);
613- }
614+ // Frame 0 should match reference
615+ EXPECT_LT (fabs (ener[0 ] - expected_tot_e), EPSILON);
616+ for (int ii = 0 ; ii < natoms * 3 ; ++ii) {
617+ EXPECT_LT (fabs (force[ii] - expected_f[ii]), EPSILON);
614618 }
619+ // Frame 1 should be different (perturbed coords)
620+ EXPECT_GT (fabs (ener[1 ] - ener[0 ]), 1e-10 );
615621}
616622
617623// ========== Parser / metadata coverage tests ==========
@@ -631,6 +637,7 @@ TEST(TestDeepPotPTExptParser, load_invalid_zip) {
631637 std::string tmpfile = " test_invalid.pt2" ;
632638 {
633639 std::ofstream ofs (tmpfile, std::ios::binary);
640+ ASSERT_TRUE (ofs.is_open ()) << " Failed to create temp file" ;
634641 ofs << " not a zip file at all" ;
635642 }
636643 deepmd::DeepPot dp;
@@ -645,6 +652,7 @@ TEST(TestDeepPotPTExptParser, load_tiny_file) {
645652 std::string tmpfile = " test_tiny.pt2" ;
646653 {
647654 std::ofstream ofs (tmpfile, std::ios::binary);
655+ ASSERT_TRUE (ofs.is_open ()) << " Failed to create temp file" ;
648656 ofs << " abc" ;
649657 }
650658 deepmd::DeepPot dp;
0 commit comments