def testExpectedFromMergingOrderedStructs(self):
     expKwargDict = {
         "step": self.stepsA + self.stepsB,
         "temp": self.tempA + self.tempB
     }
     expObj = tCode.ThermoDataStandard(expKwargDict)
     actObj = tCode.getMergedStandardThermoData(
         self.dataList, overlapStrat=self.overlapStrat)
     self.assertEqual(expObj, actObj)
Ejemplo n.º 2
0
def parseMdInfoFromMultipleCpoutAndXyzPaths(cpoutPaths,
                                            xyzPaths,
                                            tempKindPaths=None,
                                            velocityPaths=None,
                                            forcePaths=None):
    """ Parse an MD trajectory spread over multiple cp2k restarts
	
	Args:
		cpoutPaths: (iter of str) Paths to *.cpout files
		xyzPaths: (iter of str) Paths to *.xyz files
		tempKindPaths: (iter of str, Optional) Paths to files containing atomic temperatures
		velocityPaths: (iter of str, Optional) Paths to files containing velocities as dumped by motion section (basically an xyz format)
		forcePaths: (iter of str, Optional) Paths to files containing forces as dumped by motion section (basically an xyz format)

	Returns
		outDict: Contains trajectory/thermodynamic info
 
	"""
    outDict = dict()
    tempKindPaths = [None for x in range(len(cpoutPaths))
                     ] if tempKindPaths is None else tempKindPaths
    velocityPaths = [None for x in range(len(cpoutPaths))
                     ] if velocityPaths is None else velocityPaths
    forcePaths = [None for x in range(len(cpoutPaths))
                  ] if forcePaths is None else forcePaths

    #1) Get all the dicts
    parsedDicts = list()
    for cpoutPath, xyzPath, tKindPath, vPath, fPath in it.zip_longest(
            cpoutPaths, xyzPaths, tempKindPaths, velocityPaths, forcePaths):
        currDict = parseFullMdInfoFromCpoutAndXyzFilePaths(
            cpoutPath,
            xyzPath,
            tempKindPath=tKindPath,
            velocityPath=vPath,
            forcePath=fPath)
        parsedDicts.append(currDict)

    #2) Merge all the trajectories
    allTraj = [currDict["trajectory"] for currDict in parsedDicts]
    mergedTraj = trajHelp.getMergedTrajInMemory(allTraj)
    outDict["trajectory"] = mergedTraj

    #3) Merge the thermo data
    allThermoData = [currDict["thermo_data"] for currDict in parsedDicts]
    mergedThermo = thermoDataHelp.getMergedStandardThermoData(allThermoData)
    outDict["thermo_data"] = mergedThermo

    return outDict
    def testExpectedStepsWithOverhang_trimStratSimple(self):
        self.stepsA = [1, 2, 3, 4, 5]
        self.stepsB = [
            4, 6
        ]  #Deleting step 5 makes it more likely we really are taking the step 4 from this set of trajs
        self.tempA = [2 * x for x in self.stepsA]
        self.tempB = [3 * x for x in self.stepsB]
        self.createTestObjs()

        expKwargDict = {
            "step": self.stepsA[:3] + self.stepsB,
            "temp": self.tempA[:3] + self.tempB
        }
        expObj = tCode.ThermoDataStandard(expKwargDict)
        actObj = tCode.getMergedStandardThermoData(
            self.dataList, overlapStrat=self.overlapStrat)
        self.assertEqual(expObj, actObj)
 def testRaisesIfDataListsNotAllTheSame(self):
     self.stepsB.append(20)
     with self.assertRaises(AssertionError):
         tCode.getMergedStandardThermoData(self.dataList,
                                           overlapStrat=self.overlapStrat)
 def testRaisesIfPropsNotTheSame(self):
     self.dataList[1].dataDict["fake_prop"] = list()
     with self.assertRaises(ValueError):
         tCode.getMergedStandardThermoData(self.dataList,
                                           overlapStrat=self.overlapStrat)