def testExpected_twoIdenticalDistrOpts(self): self.useGroups = [[0], [0]] currArgs = [ self.binResObjA, self.hyIndices ] #Neither arg should matter; hence i set the wrong value for the 2nd on purpose self.distrOptObjs = [ distrOptObjHelp.CalcPlanarDistOptions( *currArgs, planeEqn=planeEqnHelp.ThreeDimPlaneEquation(0, 0, 1, 1)), distrOptObjHelp.CalcPlanarDistOptions( *currArgs, planeEqn=planeEqnHelp.ThreeDimPlaneEquation(0, 0, 1, 1)) ] self.createTestObjs() expVals = [[self.timeA, (3, 3)], [self.timeA, (3.9, 3.9)], [self.timeB, (4, 4)]] actVals = self._runTestFunct() for currExpVal, currActVal in it.zip_longest(expVals, actVals): expTime, actTime = currExpVal[0], currActVal[0] expVals, actVals = currExpVal[1], currActVal[1] self.assertAlmostEqual(expTime, actTime) [ self.assertAlmostEqual(exp, act) for exp, act in it.zip_longest(expVals, actVals) ]
def setUp(self): self.lattParams, self.lattAngles = [10, 10, 10], [90, 90, 90] self.cartCoords = [[2, 2, 4, "Mg"], [2, 2, 1, "Mg"], [2, 2, 9, "Mg"], [2, 2, 8, "Mg"]] self.distIndicesFrom = [0, 2] self.distIndicesTo = [1, 3] self.planarEqnA = planeEqnHelp.ThreeDimPlaneEquation(0, 0, 1, 2) self.planarEqnB = planeEqnHelp.ThreeDimPlaneEquation(0, 0, 1, 2) self.planarIndicesA = [0, 2] self.planarIndicesB = [3] self.createTestObjs()
def testExpectedUsingPlaneEqnInput(self): self.surfaceDetector=None self.planeEqn = planeEqnHelp.ThreeDimPlaneEquation(0,0,1,63) #This lies at the top of the cell; hence the nearest layer is the layer furthest from the surface expFirstLayer, expSecondLayer = self._loadExpFirstAndSecondLayerDefaultSettings() expVals = [expSecondLayer, expFirstLayer] actVals = self._runTestFunct() self.assertEqual(expVals, actVals)
def testDistTol_returnsBelowWhenTopOnly(self): self.planeEqnA = planeEqnHelp.ThreeDimPlaneEquation(0, 0, 1, 5.05) self.bot = False self.createTestObjs() expIndices = [1, 2] actIndices = self._runTestFunct() self.assertEqual(expIndices, actIndices)
def testGetSurfacePlanePointingSameDirAsCVector(self): """ Want the surface plane-equation with the normal vector pointing along c for the cubic cell (and the same direction for other cells)""" expPlaneEqn = planeEqnHelp.ThreeDimPlaneEquation(0, 0, 1, 0) actPlaneEqn = tCode.getABPlaneEqnWithNormVectorSameDirAsC( self.testCellA.lattVects) self.assertEqual(expPlaneEqn, actPlaneEqn)
def testExpectedResultUsingPlaneEqnInput(self): self.surfaceDetector=None self.planeEqn = planeEqnHelp.ThreeDimPlaneEquation(0,0,1,63) #This lies at the top of the cell; hence the nearest layer is the layer furthest from the surface expSecondLayer = [ [24, 42, 43], [25, 44, 45], [26, 46, 47], [27, 48, 49], [28, 50, 51], [29, 52, 53] ] actSecondLayer = self._runTestFunct() self.assertEqual(expSecondLayer,actSecondLayer)
def testExpectedVals_sparseMatrix(self): self.planeEqn = planeEqnHelp.ThreeDimPlaneEquation(0,0,1,5) self.indices = [0,2] self.sparseMatrix = True expDists = [3,np.nan,4] actDists = self._runTestFunct() self.assertTrue( np.allclose( np.array(expDists), np.array(actDists), equal_nan=True ) )
def setUp(self): self.lattParams = [10, 9, 8] self.lattAngles = [90, 90, 90] self.fractPositions = [[0.5, 0.5, 0.5], [0.51, 0.5, 0.5]] self.atomList = ["X" for x in self.fractPositions] self.planeEqnA = planeEqnHelp.ThreeDimPlaneEquation(0, 0, 1, 1) self.testAtomIdx = 0 self.createTestObjs()
def setUp(self): #The cell self.lattParamsA, self.lattAnglesA = [10, 10, 10], [90, 90, 90] self.cartCoordsA = [[5, 5, 9, "X"], [5, 5, 1, "Y"], [6, 6, 3, "Z"]] #The indices to use for each binner self.indicesA = [0, 1, 2] self.indicesB = [0, 2] #Bin edges; self.binEdgesA = [0, 2, 4] self.binEdgesB = [0, 2, 4] #Plane equations to use for each binner self.planeEqnA = planeEqnHelp.ThreeDimPlaneEquation(0, 0, 1, 0) self.planeEqnB = planeEqnHelp.ThreeDimPlaneEquation(0, 0, 1, 0) self.createTestObjs()
def testGetSurfacePlanePointingSameDirAsCVectorUCellInterface_negativeCVector( self): lattVects = self.testCellA.lattVects lattVects[-1] = [-1 * x for x in lattVects[-1]] stubInpCell = types.SimpleNamespace(lattVects=lattVects) expPlaneEqn = planeEqnHelp.ThreeDimPlaneEquation(0, 0, -1, 0) actPlaneEqn = tCode.getABPlaneEqnWithNormVectorSameDirAsC_uCellInterface( stubInpCell) self.assertEqual(expPlaneEqn, actPlaneEqn)
def setUp(self): self.lattParams = [10, 10, 10] self.lattAngles = [90, 90, 90] self.coordsA = [[2, 2, 3, "X"], [3, 3, 3, "X"], [5, 5, 5, "Y"], [5, 5, 9, "Z"]] self.planeEqn = planeEqnHelp.ThreeDimPlaneEquation(0, 0, 1, 0) self.atomIndices = [idx for idx, unused in enumerate(self.coordsA)] self.signed = False self.createTestObjs()
def testPbcAwareVersion(self): self.planeEqnA = planeEqnHelp.ThreeDimPlaneEquation(0, 0, 1, 0) self.coordsA = [[4, 4, 2, "X"], [5, 5, 5, "X"], [6, 6, 9, "X"]] self.maxDist = 3 self.minImageConv = True self.createTestObjs() self.inpIndices = [0, 2] expIndices = [0, 2] actIndices = self._runTestFunct() self.assertEqual(expIndices, actIndices)
def setUp(self): self.lattParams, self.lattAngles = [10, 10, 10], [90, 90, 90] self.coordsA = [[5, 5, 5, "X"], [5, 6, 8, "X"], [5, 7, 8, "X"], [5, 8.5, 8, "X"]] self.inpPointsA = [[5, 6, 2, "X"], [5, 7, 1, "X"]] self.maxDist = 2 self.planeEqn = planeEqnHelp.ThreeDimPlaneEquation(0, 0, 1, 5) self.createTestObjs()
def setUp(self): self.lattParams, self.lattAngles = [10,10,10], [90,90,90] self.cartCoords = [ [2,2,2,"X"], [3,3,6,"Y"], [4,4,9,"Z"] ] self.indices = [0,1,2] self.planeEqn = planeEqnHelp.ThreeDimPlaneEquation(0,0,1,0) self.sparseMatrix = False self.createTestObjs()
def setUp(self): self.lattParams, self.lattAngles = [10, 10, 10], [90, 90, 90] self.cartCoords = [[2, 2, 4, "Mg"], [2, 2, 1, "Mg"], [2, 2, 9, "Mg"], [2, 2, 8, "Mg"]] self.indices = [0, 2] self.planeEqnA = planeEqnHelp.ThreeDimPlaneEquation(0, 0, 1, 2) self.objLevel = 0 self.callLevel = 0 self.createTestObjs()
def setUp(self): self.top = True self.bot = True self.maxDist = 3 self.distTol = 1e-1 self.planeEqnA = planeEqnHelp.ThreeDimPlaneEquation(0, 0, 1, 5) self.lattParams = [10, 10, 10] self.lattAngles = [90, 90, 90] self.coordsA = [[4, 4, 4, "X"], [5, 5, 5, "X"], [6, 6, 6, "X"]] self.minImageConv = False self.createTestObjs()
def setUp(self): #Geom for testing the alternative initializer self.lattParams, self.lattAngles = [10,10,10], [90,90,90] self.cartCoords = [ [0,0,0,"O"], [1,1,1,"H"], [2,2,2,"H"], [3,3,3,"O"], [4,4,4,"H"], [5,5,5,"H"] ] #Options for the actual opts obj self.oxyIndices = [3,0] self.hyIndices = [[4,5],[1,2]] self.planeEqn = planeEqnHelp.ThreeDimPlaneEquation(0,0,1,5) self.primaryIdxType = "O" self.binResObj = 5 #Int has functionally similar equality method to the binRes obj so... self.createTestObjs()
def testExpectedCaseB_matrixAlreadyPresent(self): self.outDict["planarDists"] = [np.empty((6)), np.empty((6))] self.outDict["uniquePlaneEquations"] = [ planeEqnHelp.ThreeDimPlaneEquation(0, 0, 1, 6), self.planeEqn ] self.outDict["planarDists"][0][:], self.outDict["planarDists"][ 1][:] = np.nan, np.nan self.outDict["planarDists"][1][0] = 4 self._runTestFunct() expMatrix = np.empty((6)) expMatrix[:] = np.nan expMatrix[0] = 4 expMatrix[3] = 1 expUniquePlaneEqns = [ planeEqnHelp.ThreeDimPlaneEquation(0, 0, 1, 6), self.planeEqn ] actMatrix = self.outDict["planarDists"][1] actUniquePlaneEqns = self.outDict["uniquePlaneEquations"] self.assertEqual(expUniquePlaneEqns, actUniquePlaneEqns) self.assertTrue(np.allclose(expMatrix, actMatrix, equal_nan=True))
def setUp(self): #Some coords self.lattParams, self.lattAngles = [10,10,10], [90,90,90] self.coords = [ [2,2,2,"Mg"], [2,2,6, "O"], [2,2,4, "O"], [2,2,5,"Mg"] ] #Options for planar distance self.planeEqn = planeEqnHelp.ThreeDimPlaneEquation(0,0,1,5) self.planarIndices = [0,1] self.fromIndices = [0,1] self.toIndices = [2,3] self.createTestObjs()
def setUp(self): #1) All geometric parameters for testing self.lattParams, self.lattAngles = [10,10,10], [90,90,90] #pitch=90, OH len~1, HOH angle 104.5. Then just added translation vectors (also rounded coords) self.waterACoords = [ [0.0, 0.0, 0.0, 'O'], [0, 0.79, 0.61, 'H'], [0, -0.79, 0.61, 'H'] ] self.waterBCoords = [ [0.0, 0.0, 5.0, 'O'], [0, 0.79, 5.61, 'H'], [0, -0.79, 5.61, 'H']] self.coords = self.waterACoords + self.waterBCoords self.outDict = dict() #Options for the populator self.primaryIdxType = "O" self.planeEqn = planeEqnHelp.ThreeDimPlaneEquation(0,0,1,4) self.oxyIndices = [0,3] self.hyIndices = [ [1,2], [4,5] ] self.createTestObjs()
def setUp(self): #Create geometry self.lattParams, self.lattAngles = [10,10,10], [90,90,90] self.coords = [ [0,0,7,"A"], [0,0,8,"B"], [0,0,9,"C"], [0,0,1,"D"], [0,0,2,"E"] ] #Simple options self.indicesA = [0,1] self.indicesB = [2,3,4] self.minDistAToB = False self.dudBinResObj = None self.rdfBinObj = binResHelp.BinnedResultsStandard.fromBinEdges([-0.1,10,20,30]) #Needed for filter functions self.rdfFilterBasedOnBins = True self.planeEqn = planeEqnHelp.ThreeDimPlaneEquation(0,0,1,0) self.createTestObjs()
def setUp(self): #Geometry options; coordsA has two hydroxyl while coordsB has only 1 self.lattParams, self.lattAngles = [10, 10, 10], [90, 90, 90] self.coordsA = [[0, 0, 0, "X"], [4, 4, 4, "O"], [5, 4, 4, "H"], [7, 7, 7.1, "O"], [7, 7, 8, "H"], [3, 4, 5, "X"]] #Something about this geometry stops the classifier working???? self.coordsB = [[0, 0, 0, "X"], [5, 5, 5, "O"], [6, 5, 5, "H"], [7, 7, 7, "O"], [2, 2, 2, "H"], [5, 7, 8, "X"]] self.timeA, self.timeB = 10, 20 #Not really neeeded but a non-optional argument somewhere self.binResObjA, self.binResObjB = [None, None] #Classifier options self.oxyIndices = [1, 3] self.hyIndices = [2, 4] self.maxOOHBond = 1.5 self.nNebs = [1] #Options for the planar distribution currArgs = [ self.binResObjA, self.hyIndices ] #Neither arg should matter; hence i set the wrong value for the 2nd on purpose self.distrOptObjs = [ distrOptObjHelp.CalcPlanarDistOptions( *currArgs, planeEqn=planeEqnHelp.ThreeDimPlaneEquation(0, 0, 1, 1)) ] #Options for the filtered object thing self.useGroups = [[0]] self.useNonHyIdx, self.useIdxEach = True, 0 #Options for the actual function self.foldOneDimData = True self.createTestObjs()
def testExpected_firstPlaneEqnPopulated(self): prevPlaneEqn = planeEqnHelp.ThreeDimPlaneEquation(0, 0, 1, 5) prevPlanarDistMatrix = np.empty((4)) prevPlanarDistMatrix[:] = np.nan self.outDict["uniquePlaneEquations"] = [prevPlaneEqn] self.outDict["planarDists"] = [prevPlanarDistMatrix] # expNewMatrix = np.empty((4)) expNewMatrix[:] = np.nan expNewMatrix[0], expNewMatrix[2] = 2, 3 expMatrices = [prevPlanarDistMatrix, expNewMatrix] expUniquePlaneEqns = [prevPlaneEqn, self.planeEqnA] self._runTestFunct() self.assertEqual(expUniquePlaneEqns, self.outDict["uniquePlaneEquations"]) for expMatrix, actMatrix in it.zip_longest( expMatrices, self.outDict["planarDists"]): self.assertTrue(np.allclose(expMatrix, actMatrix, equal_nan=True))
def setUp(self): self.cellA = _loadCellA() self.atomIndices = [2, 3] self.planeEqn = planeEqnHelp.ThreeDimPlaneEquation(0, 0, 1, 0)
def testExpectedDistsFromSurfPlaneAtCellMidpoint(self): self.planeEqn = planeEqnHelp.ThreeDimPlaneEquation(0,0,1,5) self.indices = [0,1,2] expDists = [3,1,4] actDists = self._runTestFunct() [self.assertAlmostEqual(e,a) for e,a in it.zip_longest(expDists, actDists)]
def testUnequalCmp_diffPlaneEqn(self): objA = copy.deepcopy(self.testObj) self.planeEqn = planeEqnHelp.ThreeDimPlaneEquation(1, 0, 1, 3) self.createTestObjs() objB = self.testObj self.assertNotEqual(objA, objB)
def setUp(self): self.indices = [0, 3] self.planeEqn = planeEqnHelp.ThreeDimPlaneEquation(0, 0, 1, 2) self.objLevel = 2 self.createTestObjs()
def testGetSurfacePlanePointingSameDirAsCVector_negativeCVector(self): lattVects = self.testCellA.lattVects lattVects[-1] = [-1 * x for x in lattVects[-1]] expPlaneEqn = planeEqnHelp.ThreeDimPlaneEquation(0, 0, -1, 0) actPlaneEqn = tCode.getABPlaneEqnWithNormVectorSameDirAsC(lattVects) self.assertEqual(expPlaneEqn, actPlaneEqn)
def testForSurfPlaneEqnInterface(self): expD = 6 expPlaneEqn = planeEqnHelp.ThreeDimPlaneEquation(0, 0, 1, expD) actPlaneEqn = tCode.getAverageSurfacePlaneEquationForAtomIndices( self.cellA, self.atomIndices) self.assertEqual(expPlaneEqn, actPlaneEqn)
def testExpectedAverageEqnA(self): expD = 6 expPlaneEqn = planeEqnHelp.ThreeDimPlaneEquation(0, 0, 1, expD) actPlaneEqn = self._runTestFunct() self.assertEqual(expPlaneEqn, actPlaneEqn)