Ejemplo n.º 1
0
 def GetSystem(self, doQCMM=True, log=logFile, nbModel=None, qcModel=None):
     """Get the system with the energy model defined."""
     # . Basic setup.
     molecule = MOLFile_ToSystem(
         os.path.join(self.dataPath, self.fileName + ".mol"))
     molecule.label = self.label
     molecule.DefineMMModel(self.mmModel)
     # . Set up the QC model.
     if qcModel is not None:
         molecule.electronicState = ElectronicState(
             charge=self.qcCharge, multiplicity=self.multiplicity)
         if doQCMM:
             molecule.DefineQCModel(qcModel, qcSelection=self.qcSelection)
         else:
             molecule.DefineQCModel(qcModel)
     # . Set up the NB model.
     if (qcModel is None) or doQCMM:
         if nbModel is None: molecule.DefineNBModel(self.nbModel)
         else: molecule.DefineNBModel(nbModel)
     # . Summary.
     if LogFileActive(log):
         molecule.Summary(log=log)
         log.Paragraph("\nFormula = " + molecule.atoms.FormulaString() +
                       ".")
     # . Finish up.
     return molecule
Ejemplo n.º 2
0
 def GetSystem(self, log=logFile, maximumAtoms=None):
     """Get the system with the energy model defined."""
     # . Get the QC model options.
     convergerKeywords = getattr(self, "convergerKeywords", {})
     qcModelArguments = getattr(self, "qcModelArguments", [])
     qcModelClass = getattr(self, "qcModelClass", None)
     qcModelKeywords = getattr(self, "qcModelKeywords", {})
     # . Basic setup.
     if self.fileFormat == "mol":
         molecule = MOLFile_ToSystem(
             os.path.join(self.dataPath, self.fileName + ".mol"))
     elif self.fileFormat == "xyz":
         molecule = XYZFile_ToSystem(
             os.path.join(self.dataPath, self.fileName + ".xyz"))
     molecule.electronicState = ElectronicState(
         charge=getattr(self, "charge", 0),
         multiplicity=getattr(self, "multiplicity", 1))
     molecule.label = self.label
     # . Only keep the molecule if it is not too large.
     if (maximumAtoms is None) or ((maximumAtoms is not None) and
                                   (len(molecule.atoms) <= maximumAtoms)):
         # . Define the QC model.
         if qcModelClass is not None:
             converger = DIISSCFConverger(**convergerKeywords)
             kwargs = dict(qcModelKeywords)
             kwargs["converger"] = converger
             qcModel = qcModelClass(*qcModelArguments, **kwargs)
             molecule.DefineQCModel(qcModel, log=log)
         # . Summary.
         if LogFileActive(log):
             molecule.Summary(log=log)
             log.Paragraph("\nFormula = " + molecule.atoms.FormulaString() +
                           ".")
     # . Molecule rejected.
     else:
         molecule = None
     # . Finish up.
     return molecule
    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 ) )
    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.º 5
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.º 6
0
    def runTest(self):
        """The test."""

        # . Initialization.
        isOK = True
        log = self.GetLog()
        molPath = os.path.join(os.getenv("PDYNAMO_PMOLECULE"), "data", "mol")

        # . Options.
        converger = DIISSCFConverger(densityTolerance=1.0e-6,
                                     maximumSCFCycles=500)
        qcModel = QCModelMNDO("am1",
                              converger=converger,
                              isSpinRestricted=False)
        singlet = ElectronicState(charge=1, multiplicity=1)
        triplet = ElectronicState(charge=1, multiplicity=3)

        # . Optimizer.
        optimizer = QuasiNewtonMinimizer(logFrequency=1,
                                         maximumIterations=500,
                                         rmsGradientTolerance=0.05)
        optimizer.Summary(log=log)

        # . Set up the system.
        system = MOLFile_ToSystem(os.path.join(molPath, "phenylCation.mol"))
        system.electronicState = singlet
        system.label = "Phenyl Cation"
        system.DefineQCModel(qcModel)
        system.Summary(log=log)

        # . Check both methods.
        numberNotConverged = 0
        results = {}
        for method in ("GP", "PF"):

            # . Reset coordinates.
            system.coordinates3 = MOLFile_ToCoordinates3(
                os.path.join(molPath, "phenylCation.mol"))
            system.configuration.Clear()

            # . Set up the objective function.
            seamOF = SEAMObjectiveFunction.FromSystem(system,
                                                      singlet,
                                                      triplet,
                                                      method=method)
            #seamOF.RemoveRotationTranslation ( )

            # . Minimize.
            #seamOF.TestGradients ( delta = 1.0e-05 ) # . Works with 1.0e-10 density tolerance.
            cpu = CPUTime()
            report = optimizer.Iterate(seamOF, log=log)
            report["CPU Time"] = cpu.CurrentAsString()

            # . Final energies.
            (f1, f2) = seamOF.Energies(doGradients=True, log=log)
            report["Energy 1"] = f1
            report["Energy 2"] = f2
            results[method] = report
            if not report.get("Converged", False): numberNotConverged += 1

        # . Print out a summary of the results.
        if LogFileActive(log):
            table = log.GetTable(columns=[10, 20, 20, 10, 10, 20])
            table.Start()
            table.Title("Surface Crossing Optimizations")
            table.Heading("Method")
            table.Heading("State Energies", columnSpan=2)
            table.Heading("Converged")
            table.Heading("Calls")
            table.Heading("Time")
            for method in ("GP", "PF"):
                report = results[method]
                table.Entry(method, alignment="left")
                table.Entry("{:20.1f}".format(report["Energy 1"]))
                table.Entry("{:20.1f}".format(report["Energy 2"]))
                table.Entry("{!r}".format(report.get("Converged", False)))
                table.Entry("{:d}".format(report["Function Calls"]))
                table.Entry(report["CPU Time"])
            table.Stop()

        # . Finish up.
        self.assertTrue(numberNotConverged == 0)