コード例 #1
0
    def runTest(self):
        """The test."""

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

        # . Conformations.
        xyzFiles = glob.glob(os.path.join(xyzPath, "*.xyz"))
        xyzFiles.sort()

        # . Generate the molecule.
        molecule = MOLFile_ToSystem(os.path.join(molPath, "bAla_c7eq.mol"))
        molecule.Summary(log=log)

        # . Initialization.
        isOK = True

        # . Loop over the structures in the xyz files.
        for xyzFile in xyzFiles:
            molecule.coordinates3 = XYZFile_ToCoordinates3(xyzFile)
            if log is not None:
                conformation = os.path.split(xyzFile)[-1].split("_",
                                                                1)[-1][0:-4]
                log.Heading("bALA Configuration " + conformation,
                            QBLANKLINE=True)
            results = CIPLabelFinder(molecule, log=log)
            if results is None:
                localIsOK = False
            else:
                ((tCenters, rtCenters, stCenters, utCenters),
                 (dCenters, edCenters, zdCenters, udCenters)) = results
                localIsOK = ( len ( tCenters  ) == 4 ) and ( len ( dCenters  ) == 0 ) and \
                            ( len ( stCenters ) == 1 ) and ( len ( utCenters ) == 3 )
            isOK = (isOK and localIsOK)

        # . Success/failure.
        self.assertTrue(isOK)
コード例 #2
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)