Ejemplo n.º 1
0
    def runTest(self):
        """The test."""

        # . Paths.
        dataPath = os.path.join(os.getenv("PDYNAMO_PMOLECULE"), "data", "mol")
        log = self.GetLog()

        # . Get the system.
        molecule = MOLFile_ToSystem(
            os.path.join(dataPath, "tyrosineDipeptide.mol"))
        molecule.DefineMMModel(MMModelOPLS("protein"))
        molecule.DefineNBModel(NBModelFull())
        molecule.Summary(log=log)
        molecule.Energy(log=log, doGradients=True)

        # . Save initial coordinates.
        reference3 = Clone(molecule.coordinates3)

        # . Do some dynamics.
        normalDeviateGenerator = NormalDeviateGenerator.WithRandomNumberGenerator(
            RandomNumberGenerator.WithSeed(247171))
        LangevinDynamics_SystemGeometry(
            molecule,
            collisionFrequency=25.0,
            log=log,
            logFrequency=1000,
            normalDeviateGenerator=normalDeviateGenerator,
            steps=_NSteps,
            temperature=300.0,
            timeStep=0.001)

        # . Check RMSs which should be the same as rotation and translation are removed.
        masses = molecule.atoms.GetItemAttributes("mass")
        rms0 = molecule.coordinates3.RMSDeviation(reference3, weights=masses)
        molecule.coordinates3.Superimpose(reference3, weights=masses)
        rms1 = molecule.coordinates3.RMSDeviation(reference3, weights=masses)

        # . Get the observed and reference data.
        observed = {"RMS Deviation": rms1}
        referenceData = TestDataSet("Rotation/Translation Removal")
        referenceData.AddDatum(
            TestReal("RMS Deviation",
                     rms0,
                     referenceData,
                     absoluteErrorTolerance=_RMSAbsoluteErrorTolerance,
                     toleranceFormat="{:.3f}",
                     valueFormat="{:.3f}"))

        # . Check for success/failure.
        if len(observed) > 0:
            results = referenceData.VerifyAgainst(observed)
            results.Summary(log=log, fullSummary=self.fullVerificationSummary)
            isOK = results.WasSuccessful()
        else:
            isOK = True
        self.assertTrue(isOK)
    def runTest ( self ):
        """The test."""

        # . Paths.
        dataPath = os.path.join ( os.getenv ( "PDYNAMO_ROOT" ), "molecularStructures", "aminoAcids", "mol" )
        log = self.GetLog ( )

        # . Models.
        mmModel = MMModelOPLS ( "protein" )
        nbModel = NBModelFull ( )

        # . Get all files.
        molFiles = glob.glob ( os.path.join ( dataPath, "*.mol" ) )
        molFiles.sort ( )

        # . Read all mol files.
        numberFailed = 0
        for molFile in molFiles:

            if log is not None: log.Text ( "\nProcessing " + molFile + ":\n" )
            molecule = MOLFile_ToSystem ( molFile )
            try:
                molecule.DefineMMModel ( mmModel, log = log )
                molecule.DefineNBModel ( nbModel )
                molecule.Summary ( log = log )
                molecule.Energy  ( log = log, doGradients = True )
            except Exception as e:
                numberFailed += 1
                if log is not None: log.Text ( "\nError occurred> " +  e.args[0] + "\n" )

        # . Summary of results.
        if log is not None:
            summary = log.GetSummary ( )
            summary.Start ( "OPLS Protein Parameter Tests" )
            summary.Entry ( "Successes", "{:d}".format ( len ( molFiles ) - numberFailed ) )
            summary.Entry ( "Failures" , "{:d}".format (                    numberFailed ) )
            summary.Stop  ( )

        # . Success/failure.
        self.assertTrue ( ( numberFailed == 0 ) )
    def runTest ( self ):
        """The test."""

        # . Paths.
        dataPath = os.path.join ( os.getenv ( "PDYNAMO_PMOLECULE" ), "data", "mol" )
        if self.resultPath is None: outPath  = os.path.join ( os.getenv ( "PDYNAMO_SCRATCH" ), _Destination )
        else:                       outPath  = os.path.join ( self.resultPath                , _Destination )
        if not os.path.exists ( outPath ): os.mkdir ( outPath )
        log = self.GetLog ( )

        # . Energy models.
        mmModel = MMModelOPLS ( "protein" )
        nbModel = NBModelFull ( )
        qcModel = QCModelMNDO ( converger = DIISSCFConverger ( densityTolerance = 1.0e-10 ) )

        # . Initialization.
        numberFailures = 0

        # . Loop over molecules.
        for moleculeLabel in _MoleculeLabels:

            # . Get the system.
            system = MOLFile_ToSystem ( os.path.join ( dataPath, moleculeLabel + ".mol" ) )
            if moleculeLabel in _QCModels:
                system.DefineQCModel ( qcModel )
            else:
                system.DefineMMModel ( mmModel, log = log )
                system.DefineNBModel ( nbModel )
            system.Summary ( log = log )
            system.Energy  ( log = log )

            # . Minimize well.
            LBFGSMinimize_SystemGeometry ( system,
                                           log                  =           log ,
                                           logFrequency         = _LogFrequency ,
                                           maximumIterations    =   _Iterations ,
                                           rmsGradientTolerance =    _Tolerance )

            # . Normal mode analysis.
            nmState = NormalModes_SystemGeometry ( system, log = log )

            # . Do a dynamics simulation: equilibration and then data collection.
            normalDeviateGenerator = NormalDeviateGenerator.WithRandomNumberGenerator ( RandomNumberGenerator.WithSeed ( _Seed ) )
            LangevinDynamics_SystemGeometry ( system                                          ,
                                              collisionFrequency     = _CollisionFrequency    ,
                                              log                    = log                    ,
                                              logFrequency           = _LogFrequency          ,
                                              normalDeviateGenerator = normalDeviateGenerator ,
                                              steps                  = _NSteps0               ,
                                              temperature            = _Temperature           ,
                                              timeStep               = 0.001                  )
            reference3 = Clone ( system.coordinates3 )
            trajectory = AmberTrajectoryFileWriter ( os.path.join ( outPath, moleculeLabel + ".crd" ), system )
            LangevinDynamics_SystemGeometry ( system                                          ,
                                              collisionFrequency     = _CollisionFrequency    ,
                                              log                    = log                    ,
                                              logFrequency           = _LogFrequency          ,
                                              normalDeviateGenerator = normalDeviateGenerator ,
                                              steps                  = _NSteps1               ,
                                              temperature            = _Temperature           ,
                                              timeStep               = 0.001                  ,
                                              trajectories           = [ ( trajectory, _SaveFrequency ) ] )

            # . Check RMSs.
            masses = system.atoms.GetItemAttributes ( "mass" )
            rms0   = system.coordinates3.RMSDeviation ( reference3, weights = masses )
            system.coordinates3.Superimpose ( reference3, weights = masses )
            rms1 = system.coordinates3.RMSDeviation ( reference3, weights = masses )
            if ( math.fabs ( rms1 - rms0 ) >= _RMSAbsoluteErrorTolerance ): numberFailures += 1

            # . Do a quasi-harmonic analysis.
            trajectory = AmberTrajectoryFileReader ( os.path.join ( outPath, moleculeLabel + ".crd" ), system )
            qhState    = QuasiHarmonic_SystemGeometry ( system, log = log, temperature = _Temperature, trajectories = [ trajectory ] )

        # . Success/failure.
        self.assertTrue ( ( numberFailures == 0 ) )
Ejemplo n.º 4
0
    def runTest(self):
        """The test."""

        # . Paths.
        dataPath = os.path.join(os.getenv("PDYNAMO_PMOLECULE"), "data", "mol")
        log = self.GetLog()

        # . Energy models.
        mmModel = MMModelOPLS("protein")
        nbModel = NBModelFull()

        # . Get the files.
        molFiles = glob.glob(os.path.join(dataPath, "*.mol"))

        # . Initialization.
        numberErrors = 0
        numberFailures = 0

        # . Loop over the files.
        for molFile in molFiles:

            try:

                # . Get the system.
                try:
                    system = MOLFile_ToSystem(molFile)
                    system.DefineMMModel(mmModel, log=log)
                    system.DefineNBModel(nbModel)
                    system.Summary(log=log)
                except:
                    continue

                # . Calculate an energy.
                eBefore = system.Energy(log=log, doGradients=True)

                # . Define all hydrogen positions as undefined.
                for (i, atom) in enumerate(system.atoms):
                    if atom.atomicNumber == 1:
                        system.coordinates3.FlagCoordinateAsUndefined(i)

                # . Build as many undefined coordinates as possible.
                randomNumberGenerator = RandomNumberGenerator.WithSeed(957197)
                BuildHydrogenCoordinates3FromConnectivity(
                    system,
                    log=log,
                    randomNumberGenerator=randomNumberGenerator)

                # . Calculate an energy if all coordinates have been defined.
                if system.coordinates3.numberUndefined > 0:
                    numberFailures += 1
                    if log is not None:
                        log.Paragraph("Not all hydrogens have been rebuilt.")
                else:
                    eAfter = system.Energy(log=log, doGradients=True)
                    if log is not None:
                        log.Paragraph(
                            "Energy difference after rebuilding = {:.1f}.".
                            format(eAfter - eBefore))

            except Exception as e:
                numberErrors += 1
                if log is not None:
                    log.Text("\nError occurred> " + e.args[0] + "\n")

        # . Success/failure.
        self.assertTrue(((numberErrors == 0) and (numberFailures == 0)))
    def runTest(self):
        """The test."""

        # . Output setup.
        dataPath = os.path.join(os.getenv("PDYNAMO_PMOLECULE"), "data", "mol")
        log = self.GetLog()

        # . Define the MM, NB and QC models.
        mmModel = MMModelOPLS("bookSmallExamples")
        nbModel = NBModelFull()
        qcModel = QCModelMNDO()

        # . Define the dimer with an MM model.
        dimer = MOLFile_ToSystem(os.path.join(dataPath, "waterDimer_cs.mol"))
        dimer.DefineMMModel(mmModel)
        dimer.Summary(log=log)

        # . Define the monomer selections.
        selection1 = Selection.FromIterable(range(0, 3))
        selection2 = Selection.FromIterable(range(3, 6))

        # . Get the monomer energies.
        e1 = self.MonomerEnergies(dimer, selection1, nbModel, qcModel, log=log)
        e2 = self.MonomerEnergies(dimer, selection2, nbModel, qcModel, log=log)

        # . Get the binding energies.
        e12 = {}
        for model1 in _Models:
            for model2 in _Models:
                key = model1 + " " + model2
                if log is not None:
                    log.Heading(model1 + "/" + model2 + " Dimer Calculation",
                                QBLANKLINE=True)
                # . Define the energy model.
                if key == "QC QC": dimer.DefineQCModel(qcModel)
                elif key == "QC MM":
                    dimer.DefineQCModel(qcModel, qcSelection=selection1)
                elif key == "MM QC":
                    dimer.DefineQCModel(qcModel, qcSelection=selection2)
                else:
                    dimer.energyModel.ClearQCModel(dimer.configuration)
                if "MM" in key: dimer.DefineNBModel(nbModel)
                dimer.Summary(log=log)
                # . Store the results.
                e12[key] = dimer.Energy(log=log) - e1[model1] - e2[model2]

        # . Output the results.
        if log is not None:
            keys = e12.keys()
            keys.sort()
            table = log.GetTable(columns=[20, 20, 20])
            table.Start()
            table.Title("Water Dimer Binding Energies")
            table.Heading("Monomer 1")
            table.Heading("Monomer 2")
            table.Heading("Binding Energy")
            for key in keys:
                (model1, model2) = key.split()
                table.Entry(model1)
                table.Entry(model2)
                table.Entry("{:.1f}".format(e12[key]))
            table.Stop()

        # . Success/failure.
        isOK = True
        for e in e12.values():
            if (e < _LowerBound) or (e > _UpperBound):
                isOK = False
                break
        self.assertTrue(isOK)
Ejemplo n.º 6
0
#   takes no (interesting) arguments.
#
# . Note on scratch names:
#
#   It has been noticed that ORCA itself can give an error when the name of the scratch directory is too long.
#   This occurs in the "%pcname" line of the ORCA input file. To cure this use a shorter name - either by resetting
#   the environment variable PDYNAMO_SCRATCH or by explicitly passing a name to the model with the "scratch" option.
#

# . Define the MM, NB and QC models.
mmModel = MMModelOPLS("bookSmallExamples")
nbModel = NBModelORCA()
qcModel = QCModelORCA("MP2:6-31G*", "EXTREMESCF", "SCFCONV10")

# . Define the molecule.
molecule = MOLFile_ToSystem(
    os.path.join(os.getenv("PDYNAMO_PMOLECULE"), "data", "mol",
                 "waterDimer_cs.mol"))

# . Define the selection for the first molecule.
firstWater = Selection.FromIterable([0, 1, 2])

# . Define the energy model.
molecule.DefineMMModel(mmModel)
molecule.DefineQCModel(qcModel, qcSelection=firstWater)
molecule.DefineNBModel(nbModel)
molecule.Summary()

# . Calculate an energy.
molecule.Energy(doGradients=True)
Ejemplo n.º 7
0
    def runTest(self):
        """The test."""

        # . Initialization.
        dataPath = os.path.join(os.getenv("PDYNAMO_PMOLECULE"), "data", "mol")
        log = self.GetLog()
        translation = Vector3.Uninitialized()

        # . Get the individual systems.
        energies = []
        molecules = []
        for (i, label) in enumerate(_Molecules):
            molecule = MOLFile_ToSystem(os.path.join(dataPath, label + ".mol"))
            molecule.label = label
            molecule.DefineMMModel(_mmModel)
            molecule.DefineNBModel(_nbModel)
            molecule.Summary(log=log)
            molecule.coordinates3.TranslateToCenter()
            molecule.configuration.Clear()
            energies.append(molecule.Energy(log=log, doGradients=True))
            molecules.append(molecule)

        # . Data initialization.
        observed = {}
        referenceData = TestDataSet("Merge/Prune Energies")

        # . Loop over the tests.
        for (testIndex, (moleculeFrequencies,
                         moleculePruneIndices)) in enumerate(_Tests):

            # . Heading.
            if log is not None:
                log.Heading("Merge/Prune Test {:d}".format(testIndex),
                            QBLANKLINE=True)

            # . Initialization.
            mergedEnergy = 0.0
            prunedEnergy = 0.0
            translation.Set(0.0)

            # . Gather items.
            index = 0
            numberAtoms = 0
            pruneIndices = []
            toMerge = []
            for (i, frequency) in enumerate(moleculeFrequencies):
                molecule = molecules[i]
                mergedEnergy += energies[i] * frequency
                for f in range(frequency):
                    cloned = Clone(molecule)
                    translation[0] += _Displacement
                    cloned.coordinates3.Translate(translation)
                    toMerge.append(cloned)
                    if index in moleculePruneIndices:
                        pruneIndices.extend(
                            range(numberAtoms,
                                  numberAtoms + len(cloned.atoms)))
                        prunedEnergy += energies[i]
                    index += 1
                    numberAtoms += len(cloned.atoms)

            # . Merging.
            merged = toMerge[0].Merge(toMerge[1:])
            merged.Summary(log=log)
            eMerged = merged.Energy(log=log)

            # . Pruning.
            pruned = merged.Prune(Selection.FromIterable(pruneIndices))
            pruned.Summary(log=log)
            ePruned = pruned.Energy(log=log)

            # . Get the observed and reference data.
            for (tag, eObserved,
                 eReference) in (("Merged Energy {:d}".format(testIndex),
                                  eMerged, mergedEnergy),
                                 ("Pruned Energy {:d}".format(testIndex),
                                  ePruned, prunedEnergy)):
                observed[tag] = eObserved
                referenceData.AddDatum(
                    TestReal(
                        tag,
                        eReference,
                        referenceData,
                        absoluteErrorTolerance=_EnergyAbsoluteErrorTolerance,
                        toleranceFormat="{:.3f}",
                        valueFormat="{:.3f}"))

        # . Finish up.
        if log is not None: log.Separator()

        # . Check for success/failure.
        if len(observed) > 0:
            results = referenceData.VerifyAgainst(observed)
            results.Summary(log=log, fullSummary=self.fullVerificationSummary)
            isOK = results.WasSuccessful()
        else:
            isOK = True

        # . Success/failure.
        self.assertTrue(isOK)