Ejemplo n.º 1
0
def setup_nmr(molecule, prefs, path='', ids=[], max=50):

    nmr_files = []
    for conformer in molecule.conformers:
        if (conformer.nmr_status == 'None' or conformer.nmr_status
                == 'pre-submission') and conformer.opt_status == 'successful':
            if prefs['NMR']['software'] == 'orca':
                conformer.nmr_in = orcasub.make_nmrin(prefs, conformer.molid,
                                                      conformer.xyz,
                                                      conformer.types,
                                                      path + 'NMR/')
            elif prefs['NMR']['software'] == 'g09':
                conformer.nmr_in = g09sub.make_nmrcom(prefs, conformer.molid,
                                                      conformer.xyz,
                                                      conformer.types,
                                                      path + 'NMR/')
            elif prefs['NMR']['software'] == 'g16':
                conformer.nmr_in = g16sub.make_nmrcom(prefs, conformer.molid,
                                                      conformer.xyz,
                                                      conformer.types,
                                                      path + 'NMR/')

            conformer.nmr_log = conformer.nmr_in.split('.')[0] + '.log'
            conformer.nmr_status = 'pre-submission'
            nmr_files.append('NMR/' + conformer.nmr_in.split('/')[-1])

    if len(nmr_files) == 0:
        print('No files to submit. . .')
        sys.exit(0)

    IN_ARRAY = 'NMR/NMR_IN_ARRAY.txt'
    with open(path + IN_ARRAY, 'w') as f:
        for file in nmr_files:
            print(file, file=f)

    system = prefs['comp']['system']
    memory = prefs['NMR']['memory']
    processors = prefs['NMR']['processors']
    walltime = prefs['NMR']['walltime']
    software = prefs['NMR']['software']

    files = len(nmr_files)
    chunks = HPCsub.get_chunks(files)
    qsub_names = []
    for ck in range(chunks):
        start = (ck * max) + 1
        end = ((ck + 1) * max)
        if end > files:
            end = files

        #header = HPCsub.make_HPC_header(jobname=jobname, system=system, nodes=1, ppn=processors, walltime=walltime, mem=memory)
        jobname = 'aE_' + molecule.molid + '_' + str(ck) + '_NMR'
        strings = HPCsub.make_HPC_batch_submission(prefs,
                                                   molecule.molid,
                                                   IN_ARRAY,
                                                   start,
                                                   end,
                                                   software=software,
                                                   jobname=jobname,
                                                   nodes=1,
                                                   ppn=processors,
                                                   walltime=walltime,
                                                   mem=memory)

        if prefs['comp']['system'] == 'PBS':
            filename = path + 'NMR_' + molecule.molid + '_' + str(ck) + '.qsub'
        elif prefs['comp']['system'] == 'slurm':
            filename = path + 'NMR_' + molecule.molid + '_' + str(
                ck) + '.slurm'
        elif prefs['comp']['system'] == 'local':
            filename = path + 'NMR_' + molecule.molid + '_' + str(ck) + '.sh'
        with open(filename, 'w') as f:
            for string in strings:
                print(string, file=f)
        qsub_names.append(filename)

    print('Created ', chunks, ' submission files. . .')
    if prefs['comp']['system'] == 'PBS':
        print('Submit the calculations using:')
        for file in qsub_names:
            print('qsub ', file)
    elif prefs['comp']['system'] == 'PBS':
        print('Submit the calculations using:')
        for file in qsub_names:
            print('bash ', file)
    elif prefs['comp']['system'] == 'slurm':
        print('Havent finished this yet, good luck pal. . . .')
Ejemplo n.º 2
0
def setup_resubmission(molecule, prefs, path=''):

    for conformer in molecule.conformers:
        optstatus = orcaread.get_opt_status(conformer.opt_log)

        if optstatus != 'successful':
            conformer.opt_in = orcasub.make_optin(prefs, conformer,
                                                  path + 'optimisation/')
            conformer.opt_log = conformer.optin.split('.')[0] + '.log'
            conformer.opt_status = 'pre-submission'
            opt_files.append(conformer.opt_in)

        nmrstatus = orcaread.get_nmr_status(conformer.nmr_log)
        if conformer.nmr_status != 'successful' and conformer.opt_status == 'successful':
            conformer.nmr_in = orcasub.make_nmrin(prefs, conformer,
                                                  path + 'nmr/')
            conformer.nmr_log = conformer.nmr_in.split('.') + '.log'
            conformer.nmr_status = 'pre-submission'
            nmr_files.append(conformer.nmr_in)

    for tag, in_files in zip(['OPT', 'NMR'], [opt_files, nmr_files]):

        system = prefs['comp']['system']
        if tag == 'OPT':
            memory = prefs['opt']['memory']
            processors = prefs['opt']['processors']
            walltime = prefs['opt']['walltime']
        if tag == 'NMR':
            memory = prefs['nmr']['memory']
            processors = prefs['nmr']['processors']
            walltime = prefs['nmr']['walltime']

        files = len(in_files)
        chunks = HPCsub.get_chunks(files)
        for ck in range(chunks):
            start = (ck * max) + 1
            end = ((ck + 1) * max)
            if end > files:
                end = files

            jobname = 'aE_' + molecule.molid + '_' + str(ck) + tag + '_RESUB'
            header = HPCsub.make_HPC_header(jobname=jobname,
                                            system=system,
                                            nodes=1,
                                            ppn=processors,
                                            walltime=walltime,
                                            mem=memory)

            strings = HPCsub.make_orca_batch_submission(
                prefs, in_files, start, end, ck)

            if prefs['comp']['system'] == 'PBS':
                filename = path + 'RESUB_' + tag + '_' + molecule.molid + '_' + str(
                    ck) + '.qsub'
            elif prefs['comp']['system'] == 'slurm':
                filename = path + 'RESUB_' + tag + '_' + molecule.molid + '_' + str(
                    ck) + '.slurm'
            elif prefs['comp']['system'] == 'localbox':
                filename = path + 'RESUB_' + tag + '_' + molecule.molid + '_' + str(
                    ck) + '.sh'
            with open(filename, 'w') as f:
                for string in header:
                    print(string, file=f)
                for string in strings:
                    print(string, file=f)

        print('Created ', len(chunks), ' ', tag, 'resubmission files. . .')
Ejemplo n.º 3
0
def conformational_search(molecule, prefs, pickle_file, path=''):
    # Read relevant preferences
    iterations = prefs['conf_search']['iterations']
    maxconfs = prefs['conf_search']['maxconfs']
    RMSthresh = prefs['conf_search']['RMSthresh']
    Ethresh = prefs['conf_search']['Ethresh']

    system = prefs['comp']['system']
    python_env = prefs['comp']['python_env']
    aE_dir = prefs['comp']['aE_directory']
    if system != 'local':
        memory = prefs['conf_search']['memory']
        processors = prefs['conf_search']['processors']
        walltime = prefs['conf_search']['walltime']
    else:
        memory = 2
        processors = 2
        walltime = '100:00:00'

    # Try reading pybel mol object from xyz named according to molname
    try:
        file = path + molecule.molid + '.xyz'
        mol = next(pyb.readfile('xyz', file))
    # If not, make a molecule xyz file and then read the pybel mol object
    except:
        file = path + molecule.molid + '_INIT.xyz'
        xyz.nmrmol_to_xyz(molecule, file, num=-404)
        mol = next(pyb.readfile('xyz', file))

    smiles = mol.write("smi").split()[0]

    scriptname = 'conf_search/do_confsearch.py'
    confsearch.make_confsearch_script(scriptname,
                                      pickle_file,
                                      smiles,
                                      iterations=iterations,
                                      RMSthresh=RMSthresh,
                                      maxconfs=maxconfs,
                                      Ethresh=Ethresh,
                                      path=path)

    jobname = 'aE_' + molecule.molid + '_confsearch'
    strings = HPCsub.make_HPC_header(jobname=jobname,
                                     system=system,
                                     nodes=1,
                                     ppn=processors,
                                     walltime=walltime,
                                     mem=memory)
    strings.append('conda activate {env:<10s}'.format(env=python_env))
    strings.append('python {0:<10s}'.format(scriptname))

    if prefs['comp']['system'] == 'PBS':
        filename = path + 'confsearch_' + molecule.molid + '_' + '.qsub'
    elif prefs['comp']['system'] == 'slurm':
        filename = path + 'confsearch_' + molecule.molid + '_' + '.slurm'
    elif prefs['comp']['system'] == 'local':
        filename = path + 'confsearch_' + molecule.molid + '_' + '.sh'

    with open(filename, 'w') as f:
        for string in strings:
            print(string, file=f)

    print('Conformational search script + submission file produced')