Exemple #1
0
    def setUp(self):
        self.nrigid = 5
        self.boxl = np.array([5, 5, 5])
        self.system = MorseBulk(self.nrigid, self.boxl)

        #         self.mindist = self.system.get_mindist()
        self.transform = TransformPeriodic()
        self.measure = MeasurePeriodic(self.boxl, permlist=[])
        self.exact_match = ExactMatchPeriodic(self.measure, accuracy=1e-5)
        self.mindist = MinDistBulk(self.boxl, self.measure)

        self.x1 = self.system.get_random_configuration()
        self.x2diff = self.system.get_random_configuration()
        self.x2same = self.x1.copy()
        self.x2trans = self.x1.copy()
        trans = np.random.random(3) * self.boxl
        self.transform.translate(self.x2trans, trans)
Exemple #2
0
 def get_compare_exact(self, **kwargs):
     if self.pot.periodic:
         permlist = self.get_permlist()
         boxlengths = np.ones(3) * self.pot.boxl
         measure = MeasurePeriodic(boxlengths, permlist)
         return ExactMatchPeriodic(measure, accuracy=.1)
     else:
         return BLJCluster.get_compare_exact(self, **kwargs)
Exemple #3
0
    def __init__(self, natoms, boxvec, rho=2., r0=1., A=1., rcut=None):
        super(MorseBulk, self).__init__(natoms, rho=rho, r0=r0, A=A, rcut=rcut)

        self.boxvec = boxvec
        self.periodic = True

        self.params.double_ended_connect.local_connect_params.NEBparams.interpolator = InterpolateLinearMeasure(
            MeasurePeriodic(self.boxvec))
Exemple #4
0
    def test1(self):
        natoms = 10
        L = 4.
        boxvec = np.ones(3) * L
        xi = np.random.uniform(0, L, 3 * natoms)
        xf = np.random.uniform(0, L, 3 * natoms)

        measure = MeasurePeriodic(boxvec)

        dist = measure.get_dist(xi, xf)

        int = InterpolateLinearMeasure(measure)

        for f in [0, .1, .2, .3, .8, .9, 1]:
            x3 = int(xi, xf, f)
            d2 = measure.get_dist(xi, x3)
            self.assertAlmostEqual(f * dist, d2)
Exemple #5
0
    def __init__(self, natoms, boxvec, ntypeA="default", **potential_kwargs):
        super(BLJBulk, self).__init__(natoms,
                                      ntypeA=ntypeA,
                                      **potential_kwargs)

        self.boxvec = np.array(boxvec)
        self.periodic = True
        self.potential_kwargs["boxvec"] = self.boxvec

        self.params.double_ended_connect.local_connect_params.NEBparams.interpolator = InterpolateLinearMeasure(
            MeasurePeriodic(self.boxvec))
Exemple #6
0
    def setUp(self):
        self.natoms = 100
        rho = .5
        boxl = (float(self.natoms) / rho)**(1. / 3)
        boxlengths = np.ones(3) * boxl + np.random.rand(3) * .1

        self.permlist = self.get_permlist()
        self.measure = MeasurePeriodic(boxlengths, self.permlist)

        self.x1 = self.get_random_configuration()
        self.x2diff = self.get_random_configuration()
        self.x2same = self.randomly_permute(self.x1.copy())

        self.exact_match = ExactMatchPeriodic(self.measure, accuracy=1e-5)
Exemple #7
0
    def __init__(self, radii, boxvec, power=2):
        super(SoftSphereSystem, self).__init__(self)

        self.radii = np.array(radii)
        self.natoms = self.radii.size
        self.boxvec = np.array(boxvec)
        self.periodic = True
        self.potential_kwargs = dict()
        self.power = power
        self.eps = 1.

        self.set_params(self.params)

        self.params.double_ended_connect.local_connect_params.NEBparams.interpolator = InterpolateLinearMeasure(
            MeasurePeriodic(self.boxvec))
    def setUp(self):
        self.nrigid = 5
        self.boxl = np.array([5,5,5])       
        self.system = MorseBulk(self.nrigid, self.boxl)

#         self.mindist = self.system.get_mindist()       
        self.transform = TransformPeriodic()         
        self.measure = MeasurePeriodic(self.boxl, permlist=[])
        self.exact_match = ExactMatchPeriodic(self.measure, accuracy=1e-5)
        self.mindist = MinDistBulk(self.boxl, self.measure)      
                
        self.x1 = self.system.get_random_configuration()
        self.x2diff = self.system.get_random_configuration()
        self.x2same = self.x1.copy()
        self.x2trans = self.x1.copy()
        trans = np.random.random(3)*self.boxl
        self.transform.translate(self.x2trans, trans)
Exemple #9
0
 def get_compare_exact(self):
     accuracy = self.params.database.accuracy
     measure = MeasurePeriodic(self.boxvec, self.get_permlist())
     compare = ExactMatchPeriodic(measure, accuracy=accuracy)
     return compare
Exemple #10
0
class TestExactMatchPeriodic(unittest.TestCase):
    def setUp(self):
        self.nrigid = 5
        self.boxl = np.array([5, 5, 5])
        self.system = MorseBulk(self.nrigid, self.boxl)

        #         self.mindist = self.system.get_mindist()
        self.transform = TransformPeriodic()
        self.measure = MeasurePeriodic(self.boxl, permlist=[])
        self.exact_match = ExactMatchPeriodic(self.measure, accuracy=1e-5)
        self.mindist = MinDistBulk(self.boxl, self.measure)

        self.x1 = self.system.get_random_configuration()
        self.x2diff = self.system.get_random_configuration()
        self.x2same = self.x1.copy()
        self.x2trans = self.x1.copy()
        trans = np.random.random(3) * self.boxl
        self.transform.translate(self.x2trans, trans)

    def randomly_permute(self, x):
        import random
        x = x.reshape(-1, 3)
        xnew = x.copy()
        for atomlist in self.permlist:
            permutation = copy.copy(atomlist)
            random.shuffle(permutation)
            xnew[atomlist, :] = x[permutation, :]
        return xnew.flatten()

    def test_exact_match(self):
        self.assertTrue(self.exact_match(self.x1, self.x2trans))

    def test_no_exact_match(self):
        self.assertFalse(self.exact_match(self.x1, self.x2diff))

    def test_exact_match_periodic(self):
        self.x2same[:3] += self.boxl
        self.assertTrue(self.exact_match(self.x1, self.x2same))

    # This test is pretty superfluous for the atomic-system case. But it doesn't take long and probably
    # doesn't hurt.
    def test_align_translate(self):
        np.random.seed(4)
        n = self.nrigid

        fail_counter = 0
        for i in range(10000):
            #             if (i%100 == 0):
            #                 print i
            self.x1 = self.system.get_random_configuration()
            self.x2diff = self.system.get_random_configuration()

            try:
                dist, x1, x2 = self.mindist(self.x1, self.x2diff)
            except RuntimeError:
                pass

            if self.exact_match(self.x2diff, x2) is False:
                fail_counter += 1

        self.assertFalse(fail_counter,
                         "bond lengths were changed %d times" % fail_counter)

    def test_align_match(self):
        np.random.seed(2)
        fail_counter = 0
        for i in range(1):
            #             if (i%100 == 0):
            #                 print i
            self.x1 = self.system.get_random_configuration()
            self.x2trans = self.x1
            translate = np.random.random(3) * self.boxl
            self.transform.translate(self.x2trans, translate)
            try:
                dist, x1, x2 = self.mindist(self.x1, self.x2trans)
            except RuntimeError:
                pass
            if (dist > 1e-5):
                fail_counter += 1
                print(dist)
        self.assertFalse(fail_counter,
                         "structure matching failed %d times" % fail_counter)

    def test_align_permutation(self):
        np.random.seed(4)
        fail_counter = 0
        for i in range(1):
            if (i % 100 == 0):
                print(i)
            self.x1 = self.system.get_random_configuration()
            self.x2diff = self.system.get_random_configuration()
            try:
                dist2, x1, x2 = self.mindist(self.x1, self.x2diff)
            except RuntimeError:
                fail_counter += 1
        self.assertFalse(fail_counter,
                         "rotational alignment failed %d times" % fail_counter)

    def test_align_improvement(self, verbose=True):
        np.random.seed(6)
        max_step = 10000
        fail_counter = 0
        ave = 0
        ave_inc = 0

        for i in range(max_step):
            if (i % 100 == 0):
                print(i)
            self.x1 = self.system.get_random_configuration()
            self.x2diff = self.system.get_random_configuration()
            dist = self.measure.get_dist(self.x1, self.x2diff)
            dist2, x1, x2 = self.mindist(self.x1, self.x2diff)

            if (dist2 > dist):
                #             if(i==10):
                fail_counter += 1
                ave_inc += dist2 - dist
                if (verbose):
                    print("x1", x1)
                    print("old x2", self.x2diff)
                    print("new x2", x2)
                    #                     print "atomistic x1", self.topology.to_atomistic(x1).flatten()
                    #                     print "atomistic x2", self.topology.to_atomistic(self.x2diff)
                    #                     print "new atomistic x2", self.topology.to_atomistic(x2)
                    print("dist", dist)
                    print("dist2", dist2)
                    print("i", i)


#                 try:
#                     import pele.utils.pymolwrapper as pym
#                     pym.start()
#
#                     x1 = self.topology.to_atomistic(x1)
#                     x2 = self.topology.to_atomistic(x2)
#                     self.x2diff = self.topology.to_atomistic(self.x2diff)
#
#                     pym.draw_rigid(x1, "A", 0.1, (1,0,0), self.system.draw_bonds)
#                     pym.draw_rigid(self.x2diff, "B", 0.1, (0,1,0), self.system.draw_bonds)
#                     pym.draw_rigid(x2, "C", 0.1, (0,0,1), self.system.draw_bonds)
#                     pym.draw_box(self.boxl, "D", 0.1)
#
# #                     pym.draw_rigid(x1[:self.nrigid*3], "A", 0.1, (1,0,0))
# #                     pym.draw_rigid(self.x2diff[:self.nrigid*3], "B", 0.1, (0,1,0))
# #                     pym.draw_rigid(x2[:self.nrigid*3], "C", 0.1, (0,0,1))
# #                     pym.draw_box(self.boxl, "D", 0.1)
#
#                 except:
#                     print "Could not draw using pymol, skipping this step"

            else:
                ave += dist - dist2

        ave = ave / max_step
        if (fail_counter > 0): ave_inc = ave_inc / fail_counter
        print("average decrease in distance", ave)
        print("average increase in distance", ave_inc)

        self.assertFalse(fail_counter,
                         "alignment failed %d times" % fail_counter)
Exemple #11
0
 def get_compare_exact(self):
     accuracy = 1e-2
     measure = MeasurePeriodic(self.boxvec, self.get_permlist())
     compare = ExactMatchPeriodic(measure, accuracy=accuracy)
     return compare
Exemple #12
0
 def get_mindist(self):
     measure = MeasurePeriodic(self.boxvec, permlist=self.get_permlist())
     return MinDistBulk(self.boxvec, measure)
class TestExactMatchPeriodic(unittest.TestCase):
    def setUp(self):
        self.nrigid = 5
        self.boxl = np.array([5,5,5])       
        self.system = MorseBulk(self.nrigid, self.boxl)

#         self.mindist = self.system.get_mindist()       
        self.transform = TransformPeriodic()         
        self.measure = MeasurePeriodic(self.boxl, permlist=[])
        self.exact_match = ExactMatchPeriodic(self.measure, accuracy=1e-5)
        self.mindist = MinDistBulk(self.boxl, self.measure)      
                
        self.x1 = self.system.get_random_configuration()
        self.x2diff = self.system.get_random_configuration()
        self.x2same = self.x1.copy()
        self.x2trans = self.x1.copy()
        trans = np.random.random(3)*self.boxl
        self.transform.translate(self.x2trans, trans)
    
    def randomly_permute(self, x):
        import random
        x = x.reshape(-1,3)
        xnew = x.copy()
        for atomlist in self.permlist:
            permutation = copy.copy(atomlist)
            random.shuffle(permutation)
            xnew[atomlist,:] = x[permutation,:]
        return xnew.flatten()
      
    def test_exact_match(self):
        self.assertTrue(self.exact_match(self.x1, self.x2trans))
         
    def test_no_exact_match(self):
        self.assertFalse(self.exact_match(self.x1, self.x2diff))

    def test_exact_match_periodic(self):
        self.x2same[:3] += self.boxl
        self.assertTrue(self.exact_match(self.x1, self.x2same))
        
        
    # This test is pretty superfluous for the atomic-system case. But it doesn't take long and probably
    # doesn't hurt.    
    def test_align_translate(self):
        np.random.seed(4)
        n = self.nrigid
                 
        fail_counter = 0
        for i in range(10000):
#             if (i%100 == 0):
#                 print i
            self.x1 = self.system.get_random_configuration()
            self.x2diff = self.system.get_random_configuration()
             
            try:        
                dist, x1, x2 = self.mindist(self.x1, self.x2diff) 
            except RuntimeError:
                pass            
 
            if self.exact_match(self.x2diff,x2) is False:
                fail_counter += 1
                         
        self.assertFalse(fail_counter, "bond lengths were changed %d times" % fail_counter)                
        
    def test_align_match(self):
        np.random.seed(2)        
        fail_counter = 0
        for i in range(1):
#             if (i%100 == 0):
#                 print i
            self.x1 = self.system.get_random_configuration()
            self.x2trans = self.x1
            translate = np.random.random(3)*self.boxl
            self.transform.translate(self.x2trans, translate)
            try:
                dist, x1, x2 = self.mindist(self.x1, self.x2trans)
            except RuntimeError:
                pass
            if (dist>1e-5):
                fail_counter+=1
                print dist
        self.assertFalse(fail_counter, "structure matching failed %d times" % fail_counter)        
        
    def test_align_permutation(self):
        np.random.seed(4)        
        fail_counter = 0
        for i in range(1):
            if (i%100 == 0):
                print i
            self.x1 = self.system.get_random_configuration()
            self.x2diff = self.system.get_random_configuration()
            try:
                dist2, x1, x2 = self.mindist(self.x1, self.x2diff)    
            except RuntimeError:
                fail_counter+=1
        self.assertFalse(fail_counter, "rotational alignment failed %d times" % fail_counter)                
            
    def test_align_improvement(self, verbose = True):
        np.random.seed(6)
        max_step = 10000        
        fail_counter = 0
        ave = 0
        ave_inc = 0
        
        for i in range(max_step):
            if (i%100 == 0):
                print i
            self.x1 = self.system.get_random_configuration()
            self.x2diff = self.system.get_random_configuration()
            dist = self.measure.get_dist(self.x1, self.x2diff)
            dist2, x1, x2 = self.mindist(self.x1, self.x2diff)

            if(dist2 > dist):
#             if(i==10):
                fail_counter += 1
                ave_inc += dist2 - dist
                if(verbose):
                    print "x1", x1
                    print "old x2", self.x2diff
                    print "new x2", x2
#                     print "atomistic x1", self.topology.to_atomistic(x1).flatten()
#                     print "atomistic x2", self.topology.to_atomistic(self.x2diff)
#                     print "new atomistic x2", self.topology.to_atomistic(x2)
                    print "dist", dist
                    print "dist2", dist2
                    print "i", i

#                 try: 
#                     import pele.utils.pymolwrapper as pym
#                     pym.start()
#  
#                     x1 = self.topology.to_atomistic(x1)
#                     x2 = self.topology.to_atomistic(x2)
#                     self.x2diff = self.topology.to_atomistic(self.x2diff)
#   
#                     pym.draw_rigid(x1, "A", 0.1, (1,0,0), self.system.draw_bonds)
#                     pym.draw_rigid(self.x2diff, "B", 0.1, (0,1,0), self.system.draw_bonds)
#                     pym.draw_rigid(x2, "C", 0.1, (0,0,1), self.system.draw_bonds) 
#                     pym.draw_box(self.boxl, "D", 0.1)  
#                     
# #                     pym.draw_rigid(x1[:self.nrigid*3], "A", 0.1, (1,0,0))
# #                     pym.draw_rigid(self.x2diff[:self.nrigid*3], "B", 0.1, (0,1,0))
# #                     pym.draw_rigid(x2[:self.nrigid*3], "C", 0.1, (0,0,1)) 
# #                     pym.draw_box(self.boxl, "D", 0.1)                     
#                                                                                    
#                 except:
#                     print "Could not draw using pymol, skipping this step"
                    
            else:
                ave += dist - dist2
                
        ave = ave/max_step
        if (fail_counter>0): ave_inc = ave_inc / fail_counter
        print "average decrease in distance", ave
        print "average increase in distance", ave_inc

        self.assertFalse(fail_counter, "alignment failed %d times" % fail_counter)