Exemplo n.º 1
0
def main(settings):
    print("Current working directory: " + os.getcwd())
    print("Initial input files: " + str(settings.InputFiles))
    print("NMR file: " + str(settings.NMRsource))
    print("Workflow: " + str(settings.Workflow))

    # Read in any text inputs and add these to the input file list

    import StructureInput

    if settings.Smiles:
        settings.InputFiles.extend(
            StructureInput.GenerateSDFFromTxt(settings.Smiles, 'Smiles'))

    if settings.Smarts:
        settings.InputFiles.extend(
            StructureInput.GenerateSDFFromTxt(settings.Smarts, 'Smarts'))

    if settings.InChIs:
        settings.InputFiles.extend(
            StructureInput.GenerateSDFFromTxt(settings.InChIs, 'InChI'))

    # Clean up input files if c in workflow - this generates a new set of 3d coordinates as a starting point

    if 'c' in settings.Workflow and len(settings.InputFiles) > 0:
        import StructureInput

        # if requested generate 3d coordinates to define any stereochemistry

        settings.InputFiles = StructureInput.CleanUp(settings.InputFiles)

    # if no structure inputs have been found at this point quit

    if len(settings.InputFiles) == 0:
        print(
            "\nNo input files were found please use -h for help with input options quitting..."
        )

        quit()

    # if g in workflow check number of stereocentres for each input and generate and diastereomers

    if ('g' in settings.Workflow):

        import InchiGen
        print("\nGenerating diastereomers...")

        FinalInputFiles = []

        nStereo = [
            StructureInput.NumberofStereoCentres(InpFile)
            for InpFile in settings.InputFiles
        ]

        if len(settings.InputFiles) == 1:

            FinalInputFiles.extend(
                InchiGen.GenDiastereomers(settings.InputFiles[0], nStereo[0],
                                          settings.SelectedStereocentres))

        else:

            for InpFile, nStereoCentres in zip(settings.InputFiles, nStereo):
                FinalInputFiles.extend(
                    InchiGen.GenDiastereomers(InpFile, nStereoCentres, []))

        settings.InputFiles = list(FinalInputFiles)

    print("Generated input files: " + str(settings.InputFiles) + '\n')

    # Create isomer data structures
    Isomers = [Isomer(f.split('.sdf')[0]) for f in settings.InputFiles]

    print("Assuming all computations are done? ... ", settings.AssumeDone)
    print("Using preexisting DFT data? ... ", settings.UseExistingInputs)

    # Run conformational search, if requested
    if ('m' in settings.Workflow) and not (settings.AssumeDone
                                           or settings.UseExistingInputs):

        print("Performing conformational search using ", end="")

        if settings.MM == 't':
            print("Tinker")
            print('\nSetting up Tinker files...')
            TinkerInputs = Tinker.SetupTinker(settings)

            print('\nRunning Tinker...')
            TinkerOutputs = Tinker.RunTinker(TinkerInputs, settings)

            Isomers = Tinker.ReadConformers(TinkerOutputs, Isomers, settings)

        elif settings.MM == 'm':
            print("MacroModel")
            print('\nSetting up MacroModel files...')
            MacroModelInputs = MacroModel.SetupMacroModel(settings)
            print("MacroModel inputs: " + str(MacroModelInputs))
            print('Running MacroModel...')
            MacroModelOutputs = MacroModel.RunMacroModel(
                MacroModelInputs, settings)
            print('\nReading conformers...')
            Isomers = MacroModel.ReadConformers(MacroModelOutputs, Isomers,
                                                settings)
            print('Energy window: ' + str(settings.MaxCutoffEnergy) +
                  ' kJ/mol')
            for iso in Isomers:
                print(iso.InputFile + ": " + str(len(iso.Conformers)) +
                      ' conformers read within energy window')
    else:
        print('No conformational search was requested. Skipping...')
        settings.ConfPrune = False

    # Prune conformations, if requested.
    # For each isomer, the conformers list is replaced with a smaller list of conformers
    if (settings.ConfPrune) and not (settings.AssumeDone
                                     or settings.UseExistingInputs):
        print('\nPruning conformers...')
        Isomers = ConfPrune.RMSDPrune(Isomers, settings)
        for iso in Isomers:
            print(iso.InputFile + ": " + str(len(iso.Conformers)) +
                  ' conformers after pruning with ' + str(iso.RMSDCutoff) +
                  'A RMSD cutoff')

    if ('n' in settings.Workflow) or ('o' in settings.Workflow) \
            or ('e' in settings.Workflow) or settings.AssumeDone:
        DFT = ImportDFT(settings.DFT)
    else:
        print('\nNo DFT calculations were requested. Skipping...')

    if not (settings.AssumeDone):

        # Run DFT optimizations, if requested
        if ('o' in settings.Workflow):

            now = datetime.datetime.now()
            settings.StartTime = now.strftime('%d%b%H%M')

            print('\nSetting up geometry optimization calculations...')
            Isomers = DFT.SetupOptCalcs(Isomers, settings)
            print('\nRunning geometry optimization calculations...')
            Isomers = DFT.RunOptCalcs(Isomers, settings)

            print('\nReading DFT optimized geometries...')

            Isomers = DFT.ReadGeometries(Isomers, settings)

            # Add convergence check here before continuing with calcs!
            if (DFT.Converged(Isomers) == False) and (settings.AssumeConverged
                                                      == False):
                print('Some of the conformers did not converge, quitting...')
                quit()

        # Run DFT single-point energy calculations, if requested
        if ('e' in settings.Workflow):

            now = datetime.datetime.now()
            settings.StartTime = now.strftime('%d%b%H%M')

            print('\nSetting up energy calculations...')
            Isomers = DFT.SetupECalcs(Isomers, settings)
            print('\nRunning energy calculations...')
            Isomers = DFT.RunECalcs(Isomers, settings)
            print('\nReading data from the output files...')
            Isomers = DFT.ReadEnergies(Isomers, settings)
            print("Energies: ")
            for iso in Isomers:
                print(iso.InputFile + ": " + str(iso.DFTEnergies))

        # Run DFT NMR calculations, if requested
        if ('n' in settings.Workflow):

            now = datetime.datetime.now()
            settings.StartTime = now.strftime('%d%b%H%M')

            print('\nSetting up NMR calculations...')
            Isomers = DFT.SetupNMRCalcs(Isomers, settings)
            print('\nRunning NMR calculations...')
            Isomers = DFT.RunNMRCalcs(Isomers, settings)
            print('\nReading data from the output files...')
            Isomers = DFT.ReadShieldings(Isomers)
            print("Shieldings: ")
            for iso in Isomers:
                print(iso.InputFile + ": ")
                for conf in iso.ConformerShieldings:
                    print(str(conf))

            Isomers = DFT.ReadEnergies(Isomers, settings)
            print("Energies: ")
            for iso in Isomers:
                print(iso.InputFile + ": " + str(iso.DFTEnergies))

    else:
        # Read DFT optimized geometries, if requested
        if ('o' in settings.Workflow):
            Isomers = DFT.GetPrerunOptCalcs(Isomers)
        if ('e' in settings.Workflow):
            Isomers = DFT.GetPrerunECalcs(Isomers)
        if ('n' in settings.Workflow):
            Isomers = DFT.GetPrerunNMRCalcs(Isomers)

        Isomers = DFT.ReadGeometries(Isomers, settings)

        # Read DFT NMR data, if requested
        if ('n' in settings.Workflow):
            Isomers = DFT.ReadShieldings(Isomers)
            Isomers = DFT.ReadEnergies(Isomers, settings)

    if not (NMR.NMRDataValid(Isomers)) or ('n' not in settings.Workflow):
        print('\nNo NMR data calculated, quitting...')
        quit()

    if ('s' in settings.Workflow) or ('a' in settings.Workflow):

        print('\nSetting TMS computational NMR shielding constant references')
        settings.TMS_SC_C13, settings.TMS_SC_H1 = NMR.GetTMSConstants(settings)

        print('\nConverting DFT data to NMR shifts...')
        Isomers = NMR.CalcBoltzmannWeightedShieldings(Isomers)
        Isomers = NMR.CalcNMRShifts(Isomers, settings)

        print('\nReading experimental NMR data...')
        NMRData = NMR.NMRData(settings)
        """
        print("Conformation data:")
        NMR.PrintConformationData(Isomers)
        """

        if NMRData.Type == 'desc':

            print('Experimental NMR description found and read.')

            # performs a pairwise assignment
            Isomers = NMR.PairwiseAssignment(Isomers, NMRData)

            print('Cshifts: ' + str(NMRData.Cshifts))
            print('Hshifts: ' + str(NMRData.Hshifts))

            print('Equivalents: ' + str(NMRData.Equivalents))
            print('Omits: ' + str(NMRData.Omits))

        elif NMRData.Type == "fid":

            for f in settings.NMRsource:

                if f.name == "Proton" or f.name == "proton":

                    from Proton_assignment import AssignProton
                    from Proton_plotting import PlotProton

                    print('\nAssigning proton spectrum...')
                    Isomers = AssignProton(NMRData, Isomers, settings)

                    if settings.GUIRunning == False:
                        print('\nPlotting proton spectrum...')
                        PlotProton(NMRData, Isomers, settings)

                elif f.name == "Carbon" or f.name == "carbon":

                    from Carbon_assignment import AssignCarbon
                    from Carbon_plotting import PlotCarbon

                    print('\nAssigning carbon spectrum...')
                    Isomers = AssignCarbon(NMRData, Isomers, settings)

                    if settings.GUIRunning == False:
                        print('\nPlotting carbon spectrum...')
                        PlotCarbon(NMRData, Isomers, settings)

        elif NMRData.Type == "jcamp":

            for f in settings.NMRsource:

                if f.name == "Proton.dx" or f.name == "proton.dx":

                    from Proton_assignment import AssignProton
                    from Proton_plotting import PlotProton

                    print('\nAssigning proton spectrum...')
                    Isomers = AssignProton(NMRData, Isomers, settings)

                    if settings.GUIRunning == False:
                        print('\nPlotting proton spectrum...')
                        PlotProton(NMRData, Isomers, settings)

                elif f.name == "Carbon.dx" or f.name == "carbon.dx":

                    from Carbon_assignment import AssignCarbon
                    from Carbon_plotting import PlotCarbon

                    print('\nAssigning carbon spectrum...')
                    Isomers = AssignCarbon(NMRData, Isomers, settings)

                    if settings.GUIRunning == False:
                        print('\nPlotting carbon spectrum...')
                        PlotCarbon(NMRData, Isomers, settings)

            print('Raw FID NMR datafound and read.')

        # print('\nProcessing experimental NMR data...')

        # NMRdata = NMR.ProcessNMRData(Isomers, settings.NMRsource, settings)

    if 's' in settings.Workflow:

        print('\nCalculating DP4 probabilities...')
        DP4data = DP4.DP4data()
        DP4data = DP4.ProcessIsomers(DP4data, Isomers)
        DP4data = DP4.InternalScaling(DP4data)
        DP4data = DP4.CalcProbs(DP4data, settings)
        DP4data = DP4.CalcDP4(DP4data)
        DP4data = DP4.MakeOutput(DP4data, Isomers, settings)

        # print(DP4.FormatData(DP4data))

    else:
        print('\nNo DP4 analysis requested.')
        NMRData = []
        DP4data = []

    print('\nPyDP4 process completed successfully.')

    return NMRData, Isomers, settings, DP4data
Exemplo n.º 2
0
def main(settings):

    print("==========================")
    print("PyDP4 script,\nintegrating Tinker/MacroModel,")
    print("Gaussian/NWChem and DP4\nv1.0")
    print("\nCopyright (c) 2015-2019 Kristaps Ermanis, Alexander Howarth, Jonathan M. Goodman")
    print("Distributed under MIT license")
    print("==========================\n\n")

    print("Initial input files: " + str(settings.InputFiles))
    print("NMR file: " + str(settings.NMRsource))
    print("Workflow: " + str(settings.Workflow))

    # Check the number of input files, generate some if necessary
    if ('g' in settings.Workflow) and len(settings.InputFiles) == 1:
        import InchiGen
        print("\nGenerating diastereomers...")
        settings.InputFiles = InchiGen.GenDiastereomers(settings.InputFiles[0], settings.SelectedStereocentres)

    print("Generated input files: " + str(settings.InputFiles) + '\n')

    # Create isomer data structures
    Isomers = [Isomer(f.split('.sdf')[0]) for f in settings.InputFiles]

    # Run conformational search, if requested

    print("assume",settings.AssumeDone )

    print("Use exist",settings.UseExistingInputs)

    if ('m' in settings.Workflow) and not (settings.AssumeDone or settings.UseExistingInputs):

        print("in")

        print(settings.MM)

        if settings.MM == 't':
            print('\nSetting up Tinker files...')
            TinkerInputs = Tinker.SetupTinker(settings)

            print('\nRunning Tinker...')
            TinkerOutputs = Tinker.RunTinker(TinkerInputs, settings)

            Isomers = Tinker.ReadConformers(TinkerOutputs, Isomers, settings)

        elif settings.MM == 'm':
            print('\nSetting up MacroModel files...')
            MacroModelInputs = MacroModel.SetupMacroModel(settings)
            print("MacroModel inputs: " + str(MacroModelInputs))
            print('Running MacroModel...')
            MacroModelOutputs = MacroModel.RunMacroModel(MacroModelInputs, settings)
            print('\nReading conformers...')
            Isomers = MacroModel.ReadConformers(MacroModelOutputs, Isomers, settings)
            print('Energy window: ' + str(settings.MaxCutoffEnergy) + ' kJ/mol')
            for iso in Isomers:
                print(iso.InputFile + ": "+ str(len(iso.Conformers)) + ' conformers read within energy window' )
    else:
        print('No conformational search was requested. Skipping...')
        settings.ConfPrune = False

    # Prune conformations, if requested.
    # For each isomer, the conformers list is replaced with a smaller list of conformers
    if (settings.ConfPrune) and not(settings.AssumeDone or settings.UseExistingInputs):
        print('\nPruning conformers...')
        Isomers = ConfPrune.RMSDPrune(Isomers, settings)
        for iso in Isomers:
            print(iso.InputFile + ": " + str(len(iso.Conformers)) + ' conformers after pruning with ' +
                  str(iso.RMSDCutoff) + 'A RMSD cutoff')

    if ('n' in settings.Workflow) or ('o' in settings.Workflow) \
            or ('e' in settings.Workflow) or settings.AssumeDone:
        DFT = ImportDFT(settings.DFT)
    else:
        print('\nNo DFT calculations were requested. Skipping...')

    if not(settings.AssumeDone):

        # Run DFT optimizations, if requested
        if ('o' in settings.Workflow):

            now = datetime.datetime.now()
            settings.StartTime = now.strftime('%d%b%H%M')

            print('\nSetting up geometry optimization calculations...')
            Isomers = DFT.SetupOptCalcs(Isomers, settings)
            print('\nRunning geometry optimization calculations...')
            Isomers = DFT.RunOptCalcs(Isomers, settings)

            print('\nReading DFT optimized geometries...')

            Isomers = DFT.ReadGeometries(Isomers,settings)

            #Add convergence check here before continuing with calcs!
            if (DFT.Converged(Isomers) == False) and (settings.AssumeConverged == False):
                print('Some of the conformers did not converge, quitting...')
                quit()

        # Run DFT single-point energy calculations, if requested
        if ('e' in settings.Workflow):

            now = datetime.datetime.now()
            settings.StartTime = now.strftime('%d%b%H%M')

            print('\nSetting up energy calculations...')
            Isomers = DFT.SetupECalcs(Isomers, settings)
            print('\nRunning energy calculations...')
            Isomers = DFT.RunECalcs(Isomers, settings)
            print('\nReading data from the output files...')
            Isomers = DFT.ReadEnergies(Isomers, settings)
            print("Energies: ")
            for iso in Isomers:
                print(iso.InputFile + ": " + str(iso.DFTEnergies))

        # Run DFT NMR calculations, if requested
        if ('n' in settings.Workflow):

            now = datetime.datetime.now()
            settings.StartTime = now.strftime('%d%b%H%M')

            print('\nSetting up NMR calculations...')
            Isomers = DFT.SetupNMRCalcs(Isomers, settings)
            print('\nRunning NMR calculations...')
            Isomers = DFT.RunNMRCalcs(Isomers, settings)
            print('\nReading data from the output files...')
            Isomers = DFT.ReadShieldings(Isomers)
            print("Shieldings: ")
            for iso in Isomers:
                print(iso.InputFile + ": ")
                for conf in iso.ConformerShieldings:
                    print(str(conf))

            Isomers = DFT.ReadEnergies(Isomers, settings)
            print("Energies: ")
            for iso in Isomers:
                print(iso.InputFile + ": " + str(iso.DFTEnergies))

    else:
        # Read DFT optimized geometries, if requested
        if ('o' in settings.Workflow):
            Isomers = DFT.GetPrerunOptCalcs(Isomers)
        if ('e' in settings.Workflow):
            Isomers = DFT.GetPrerunECalcs(Isomers)
        if ('n' in settings.Workflow):
            Isomers = DFT.GetPrerunNMRCalcs(Isomers)

        Isomers = DFT.ReadGeometries(Isomers, settings)

        # Read DFT NMR data, if requested
        if ('n' in settings.Workflow):
            Isomers = DFT.ReadShieldings(Isomers)
            Isomers = DFT.ReadEnergies(Isomers, settings)

    if not(NMR.NMRDataValid(Isomers)) or ('n' not in settings.Workflow):

        print('\nNo NMR data calculated, quitting...')
        quit()

    if ('s' in settings.Workflow) or ('a' in settings.Workflow):

        print('\nSetting TMS computational NMR shielding constant references')
        settings.TMS_SC_C13, settings.TMS_SC_H1 = NMR.GetTMSConstants(settings)

        print('\nConverting DFT data to NMR shifts...')
        Isomers = NMR.CalcBoltzmannWeightedShieldings(Isomers)
        Isomers = NMR.CalcNMRShifts(Isomers, settings)

        print('\nReading experimental NMR data...')
        NMRData = NMR.NMRData(settings)

        """
        print("Conformation data:")
        NMR.PrintConformationData(Isomers)
        """

        if NMRData.Type == 'desc':

            print('Experimental NMR description found and read.')

            # performs a pairwise assignment

            Isomers = NMR.PairwiseAssignment(Isomers,NMRData)

            print('Cshifts: ' + str(NMRData.Cshifts))
            print('Hshifts: ' + str(NMRData.Hshifts))

            print('Equivalents: ' + str(NMRData.Equivalents))
            print('Omits: ' + str(NMRData.Omits))

        elif NMRData.Type == "fid":

            if os.path.exists(str(settings.NMRsource) + "/Proton"):

                from Proton_assignment import AssignProton

                from Proton_plotting import PlotProton

                print('\nAssigning proton spectrum...')
                Isomers = AssignProton(NMRData,Isomers,settings)

                print('\nPlotting proton spectrum...')
                PlotProton(NMRData, Isomers, settings)

            if os.path.exists(str(settings.NMRsource) + "/Carbon"):

                from Carbon_assignment import AssignCarbon

                from Carbon_plotting import PlotCarbon

                print('\nAssigning carbon spectrum...')
                Isomers = AssignCarbon(NMRData,Isomers,settings)

                print('\nPlotting carbon spectrum...')
                PlotCarbon(NMRData, Isomers, settings)

        elif NMRData.Type == "jcamp":

            if os.path.exists(str(settings.NMRsource) + "/Proton.dx"):
                from Proton_assignment import AssignProton

                from Proton_plotting import PlotProton

                print('\nAssigning proton spectrum...')
                Isomers = AssignProton(NMRData, Isomers, settings)

                print('\nPlotting proton spectrum...')
                PlotProton(NMRData, Isomers, settings)

            if os.path.exists(str(settings.NMRsource) + "/Carbon.dx"):
                from Carbon_assignment import AssignCarbon

                from Carbon_plotting import PlotCarbon

                print('\nAssigning carbon spectrum...')
                Isomers = AssignCarbon(NMRData, Isomers, settings)

                print('\nPlotting carbon spectrum...')
                PlotCarbon(NMRData, Isomers, settings)

            print('Raw FID NMR datafound and read.')

        #print('\nProcessing experimental NMR data...')

        #NMRdata = NMR.ProcessNMRData(Isomers, settings.NMRsource, settings)

    if 's' in settings.Workflow:

        print('\nCalculating DP4 probabilities...')

        DP4data = DP4.DP4data()

        DP4data = DP4.ProcessIsomers(DP4data,Isomers)

        DP4data = DP4.InternalScaling(DP4data)

        DP4data = DP4.CalcProbs(DP4data,settings)

        DP4data = DP4.CalcDP4(DP4data)

        DP4data = DP4.MakeOutput(DP4data,Isomers,settings)

        #print(DP4.FormatData(DP4data))

    else:
        print('\nNo DP4 analysis requested.')
        NMRData = []
        DP4data = []

    print('\nPyDP4 process completed successfully.')

    return NMRData, Isomers, settings, DP4data