class LJCutTest(unittest.TestCase): def setUp(self): self.natoms = 10 self.coords = np.random.uniform(-1,1.,3*self.natoms) * self.natoms**(-1./3) self.pot = LJCut() self.E = self.pot.getEnergy(self.coords) self.Egrad, self.grad = self.pot.getEnergyGradient(self.coords) import itertools self.ilist = [] #np.zeros([self.natoms*(self.natoms-1)/2, 2]) k = 0 for i in range(self.natoms): for j in range(i): k += 1 self.ilist.append( [i,j] ) self.ilist = np.array(self.ilist) #print self.ilist def test_grad_e(self): self.assertAlmostEqual(self.E, self.Egrad, 7) def test_lists_e(self): e = self.pot.getEnergyList(self.coords, self.ilist) self.assertAlmostEqual(self.E, e, 7) def test_lists_eg(self): e, g = self.pot.getEnergyGradientList(self.coords, self.ilist) self.assertAlmostEqual(self.E, e, 7) gdiffmax = np.max(np.abs( g-self.grad )) / np.max(np.abs(self.grad)) self.assertLess(gdiffmax, 1e-7)
class LJCutTest(unittest.TestCase): def setUp(self): self.natoms = 10 self.coords = np.random.uniform( -1, 1., 3 * self.natoms) * self.natoms**(-1. / 3) self.pot = LJCut() self.E = self.pot.getEnergy(self.coords) self.Egrad, self.grad = self.pot.getEnergyGradient(self.coords) self.ilist = [] # np.zeros([self.natoms*(self.natoms-1)/2, 2]) k = 0 for i in range(self.natoms): for j in range(i): k += 1 self.ilist.append([i, j]) self.ilist = np.array(self.ilist) # print self.ilist def test_grad_e(self): self.assertAlmostEqual(self.E, self.Egrad, 7) def test_lists_e(self): e = self.pot.getEnergyList(self.coords, self.ilist) self.assertAlmostEqual(self.E, e, 7) def test_lists_eg(self): e, g = self.pot.getEnergyGradientList(self.coords, self.ilist) self.assertAlmostEqual(self.E, e, 7) gdiffmax = np.max(np.abs(g - self.grad)) / np.max(np.abs(self.grad)) self.assertLess(gdiffmax, 1e-7)
def setUp(self): self.natoms = 10 self.coords = np.random.uniform( -1, 1., 3 * self.natoms) * self.natoms**(-1. / 3) self.pot = LJCut() self.E = self.pot.getEnergy(self.coords) self.Egrad, self.grad = self.pot.getEnergyGradient(self.coords) self.ilist = [] # np.zeros([self.natoms*(self.natoms-1)/2, 2]) k = 0 for i in range(self.natoms): for j in range(i): k += 1 self.ilist.append([i, j]) self.ilist = np.array(self.ilist)
def setUp(self): self.natoms = 10 self.coords = np.random.uniform(-1, 1., 3 * self.natoms) * self.natoms ** (-1. / 3) self.pot = LJCut() self.E = self.pot.getEnergy(self.coords) self.Egrad, self.grad = self.pot.getEnergyGradient(self.coords) self.ilist = [] # np.zeros([self.natoms*(self.natoms-1)/2, 2]) k = 0 for i in range(self.natoms): for j in range(i): k += 1 self.ilist.append([i, j]) self.ilist = np.array(self.ilist)
def makeBLJNeighborListPotFreeze(natoms, frozenlist, ntypeA=None, rcut=2.5, boxl=None): """ create the potential object for the kob andersen binary lennard jones with frozeen particles Parameters ---------- natoms : number of atoms in the system frozenlist : list of frozen atoms ntypeA : number of atoms of type A. It is assumed that they have indices in [0,ntypeA] rcut : the cutoff for the lj potential in units of sigA boxl : the box length for periodic box. None for no periodic boundary conditions """ print "making BLJ neighborlist potential", natoms, ntypeA, rcut, boxl if ntypeA is None: ntypeA = int(natoms * 0.8) Alist = range(ntypeA) Blist = range(ntypeA, natoms) frozenA = np.array([i for i in Alist if i in frozenlist]) mobileA = np.array([i for i in Alist if i not in frozenlist]) frozenB = np.array([i for i in Blist if i in frozenlist]) mobileB = np.array([i for i in Blist if i not in frozenlist]) blj = ljpshift.LJpshift(natoms, ntypeA, rcut=rcut) ljAA = LJCut(eps=blj.AA.eps, sig=blj.AA.sig, rcut=rcut * blj.AA.sig, boxl=boxl) ljBB = LJCut(eps=blj.BB.eps, sig=blj.BB.sig, rcut=rcut * blj.BB.sig, boxl=boxl) ljAB = LJCut(eps=blj.AB.eps, sig=blj.AB.sig, rcut=rcut * blj.AB.sig, boxl=boxl) # ten lists in total # nlAA_ff # nlAA_mm # nlAA_mf # nlBB_ff # nlBB_mm # nlBB_mf # nlAB_ff # nlAB_mm # nlAB_mf # nlAB_fm nlAA_ff = NeighborListSubsetBuild(natoms, rcut, frozenA, boxl=boxl) nlAA_mm = NeighborListSubsetBuild(natoms, rcut, mobileA, boxl=boxl) nlAA_mf = NeighborListSubsetBuild(natoms, rcut, mobileA, Blist=frozenA, boxl=boxl) nlBB_ff = NeighborListSubsetBuild(natoms, rcut, frozenB, boxl=boxl) nlBB_mm = NeighborListSubsetBuild(natoms, rcut, mobileB, boxl=boxl) nlBB_mf = NeighborListSubsetBuild(natoms, rcut, mobileB, Blist=frozenB, boxl=boxl) nlAB_ff = NeighborListSubsetBuild(natoms, rcut, frozenA, Blist=frozenB, boxl=boxl) nlAB_mm = NeighborListSubsetBuild(natoms, rcut, mobileA, Blist=mobileB, boxl=boxl) nlAB_mf = NeighborListSubsetBuild(natoms, rcut, mobileA, Blist=frozenB, boxl=boxl) nlAB_fm = NeighborListSubsetBuild(natoms, rcut, mobileB, Blist=frozenA, boxl=boxl) potlist_frozen = [ NeighborListPotentialBuild(nlAA_ff, ljAA), NeighborListPotentialBuild(nlBB_ff, ljBB), NeighborListPotentialBuild(nlAB_ff, ljAB) ] potlist_mobile = [ NeighborListPotentialBuild(nlAA_mm, ljAA), NeighborListPotentialBuild(nlAA_mf, ljAA), NeighborListPotentialBuild(nlBB_mm, ljBB), NeighborListPotentialBuild(nlBB_mf, ljBB), NeighborListPotentialBuild(nlAB_mm, ljAB), NeighborListPotentialBuild(nlAB_mf, ljAB), NeighborListPotentialBuild(nlAB_fm, ljAB), ] # wrap the mobile potentials so the check for whether coords needs to be updated # can be done all at once mobile_pot = NeighborListPotentialMulti(potlist_mobile, natoms, rcut, boxl=boxl) # wrap the mobile and frozen potentials together mcpot = MultiComponentSystemFreeze([mobile_pot], potlist_frozen) # finally, wrap it once more in a class that will zero the gradients of the frozen atoms frozenpot = FreezePot(mcpot, frozenlist, natoms) return frozenpot