예제 #1
0
    def generateDOS(self, **kwargs):
        """ Generate DOS input files for all the compounds created """
        # Set default settings.
        settings = {
            'mode'  : 'REL',
            'nktab' : '250',
            'NE'    : '50',
            'EMIN'  : '-0.2',
            'EMAX'  : '1.0',
            'ImE'   : '0.01'
        }

        # Replace default settings with user defined settings.
        for key, value in kwargs.iteritems():
            settings[key] = value

        print('Generating DOS input files.')

        for dirname in os.listdir('.'):
            if (os.path.exists(os.path.join(dirname, 'dos.inp'))
                    is True):
                print(dirname + ' already contains dos.inp, '
                      + 'it will not be overwritten.')
            else:
                reps = {
                    'tmpDATASET' : dirname,
                    'tmpMODE'    : settings['mode'],
                    'tmpNKTAB'   : settings['nktab'],
                    'tmpNE'      : settings['NE'],
                    'tmpEMIN'    : settings['EMIN'],
                    'tmpEMAX'    : settings['EMAX'],
                    'tmpImE'     : settings['ImE']
                }
                nmod.modFile(os.path.join(dirname, 'dos.inp'),
                    os.path.join(self.templatesDir, 'dos.inp'), reps)

        print('Finish generating DOS input files.')
예제 #2
0
    def create(self, fullConc, **kwargs):
        """ Create the specified compound """
        elementsFile = os.path.join(self.templatesDir, 'elements.txt')

        # Set default settings.
        settings = {
            'mode'  : 'REL',
            'nktab' : '250',
            'NE'    : '30'
        }

        # Replace default settings with user defined settings.
        for key, value in kwargs.iteritems():
            settings[key] = value

        # Set the different concentrations
        concentrations = fullConc.split('_')
        conc = [None]*5
        for i in range(len(concentrations)):
            conc[i] = concentrations[i]

        # Set the different elements
        IT = [None]*5
        for i in range(len(self.elements)):
            IT[i] = nmod.findLine(elementsFile, self.elements[i])

        fullname = (
            self.elements[0] + conc[0]
            + self.elements[1] + conc[1]
            + self.elements[2] + conc[2]
            + self.elements[3] + conc[3]
            + self.elements[4] + conc[4]
        )

        # Check if directory already exists, if not, carry on.
        if os.path.isdir(fullConc):
            print(fullConc + ' already exists, it will not be overwritten.')
        else:
            os.makedirs(fullConc)

            # Start the creation process.
            # Take all the template files, copy it to the new directory
            # and replace the "tmp" strings with the settings.

            # POT
            reps = {
                'tmpSYSTEM' : fullname,
                'tmpALAT'   : self.alat,
                'tmpCONC1'  : conc[0],
                'tmpCONC2'  : conc[1],
                'tmpCONC3'  : conc[2],
                'tmpCONC4'  : conc[3],
                'tmpCONC5'  : conc[4],
                'tmpIT1'    : IT[0],
                'tmpIT2'    : IT[1],
                'tmpIT3'    : IT[2],
                'tmpIT4'    : IT[3],
                'tmpIT5'    : IT[4]
            }
            nmod.modFile(os.path.join(fullConc, 'pot.pot'),
                os.path.join(self.templatesDir, self.potFile + '.pot'), reps)

            # SCF
            reps = {
                'tmpDATASET' : fullname,
                'tmpMODE'    : settings['mode'],
                'tmpNKTAB'   : settings['nktab'],
                'tmpNE'      : settings['NE']
            }
            nmod.modFile(os.path.join(fullConc, 'scf.inp'),
                os.path.join(self.templatesDir, 'scf.inp'), reps)

            print(fullname + " has been created.")
예제 #3
0
    def generateBSF(self, **kwargs):
        """ Generate BSF input files for all the compounds created """
        settings = {
            'nktab' : '250',
            'NE'    : '1',
            'EMIN'  : '1.0',
            'EMAX'  : '1.0',
            'NK1'   : '60',
            'NK2'   : '60',
            'K1'    : '{1.0, 0.0, 0.0}',
            'K2'    : '{0.0, 1.0, 0.0}',
            'eRange': 0.01,
            'iterations': 0
        }

        # Replace default settings with user defined settings.
        for key, value in kwargs.iteritems():
            settings[key] = value

        print('Generating BSF input files.')

        for dirname in os.listdir('.'):
            if settings['iterations'] == 0:
                if (os.path.exists(os.path.join(dirname, 'bsf.inp'))
                        is True):
                    print(dirname + ' already contains bsf.inp, '
                          + 'it will not be overwritten.')
                else:
                    reps = {
                        'tmpDATASET' : dirname,
                        'tmpNKTAB'   : settings['nktab'],
                        'tmpNE'      : settings['NE'],
                        'tmpEMIN'    : settings['EMIN'],
                        'tmpEMAX'    : settings['EMAX'],
                        'tmpNK1'     : settings['NK1'],
                        'tmpNK2'     : settings['NK1'],
                        'tmpK1'      : settings['K1'],
                        'tmpK2'      : settings['K2']
                    }
                    nmod.modFile(os.path.join(dirname, 'bsf.inp'),
                         os.path.join(self.templatesDir, 'bsf.inp'), reps)
            else:
                energy = (settings['EMIN'] - 0.5*float(settings['eRange']))

                for i in range(settings['iterations']):
                    tmpnum = str(i + 1)
                    bsfFile = 'bsf_' + tmpnum + '.inp'

                    if (os.path.exists(os.path.join(dirname, bsfFile))
                            is True):
                        print(dirname + ' already contains ' + bsfFile + ', '
                              + 'it will not be overwritten.')
                    else:
                        energy += settings['eRange'] / settings['iterations']
                        reps = {
                            'tmpDATASET' : dirname + '_' + tmpnum,
                            'tmpNKTAB'   : settings['nktab'],
                            'tmpNE'      : 1,
                            'tmpEMIN'    : energy,
                            'tmpEMAX'    : energy,
                            'tmpNK1'     : settings['NK1'],
                            'tmpNK2'     : settings['NK1'],
                            'tmpK1'      : settings['K1'],
                            'tmpK2'      : settings['K2']
                        }
                        nmod.modFile(os.path.join(dirname, bsfFile),
                             os.path.join(self.templatesDir, 'bsf.inp'), reps)

        print('Finish generating BSF input files.')
예제 #4
0
def submitArray(mainDir, pbsFile, start, end, **kwargs):
    """ Submit many array jobs without overloading the task farm """
    # Define all the required directories.
    baseDir = os.path.join(os.path.dirname(os.path.realpath(
        inspect.getfile(inspect.currentframe()))), '..')
    templatesDir = os.path.join(baseDir, 'templates')
    jobsDir = os.path.join(baseDir, mainDir, 'jobs')

    # Set default settings.
    settings = {
        'step': 10,
        'interval': 300
    }

    # Replace default settings with user defined settings.
    for key, value in kwargs.iteritems():
        settings[key] = value

    if checkRequired(mainDir, templatesDir, jobsDir):
        nmod.nexit()
    else:
        os.chdir(jobsDir)

    iterations = int(math.ceil((end - start) / settings['step']))
    last = iterations - 1 # Last iteration point for checks later.
    subCmd = ['qsub', pbsFile]
    checkInterval = settings['interval']

    timeStart = int(time.time())
    timePrev = timeStart

    # Submit the first batch of jobs.
    reps = {
        'tmpTSTART' : start,
        'tmpTEND'   : settings['step'] + start - 1
    }
    nmod.modFile(pbsFile,
        os.path.join(templatesDir, pbsFile), reps)
    subprocess.Popen(subCmd)

    for i in range(1, iterations):
        # Check if any jobs are still idle or blocked.
        # If there are, check again after an interval.
        # Only submit the next batch of jobs when there are no queued jobs.
        time.sleep(3) # Sleep to make sure the jobs are submitted.

        while True:
            # Read in the showq command as an array separated by newline.
            p = subprocess.Popen(['showq', '-u', 'phukgm'],
                                 stdout = subprocess.PIPE,
                                 stderr = subprocess.PIPE)
            stdout, _ = p.communicate()
            stdout = stdout.decode()
            stdout = stdout.split('\n')

            # Check if queued jobs are non-zero.
            if ('Idle Jobs: 0' in stdout[-2]
                    and 'Blocked Jobs: 0' in stdout[-2]):
                timePrev = time.time()
                break
            else:
                print('There are still idle and blocked jobs after '
                      + nmod.seconds2str(time.time() - timePrev) + '.')
                timePrev = time.time()
                time.sleep(checkInterval) # Check jobs interval.


        # Submit the next batch of jobs.
        # Make sure the last iteration has the correct
        # ending point of -t (tempTEND).
        if i == last:
            print('Submitting -t ' + str(i * settings['step'] + start)
                  + '-' + str(end) + '...')
            reps = {
                'tmpTSTART' : i * settings['step'] + start,
                'tmpTEND'   : end
            }
        else:
            print('Submitting -t ' + str(i * settings['step'] + start)
                  + '-' + str((i+1) * settings['step'] + start - 1) + '...')
            reps = {
                'tmpTSTART' : i * settings['step'] + start,
                'tmpTEND'   : (i+1) * settings['step'] + start - 1
            }

        nmod.modFile(pbsFile,
            os.path.join(templatesDir, pbsFile), reps)
        subprocess.Popen(subCmd)

    timeTaken = nmod.seconds2str(time.time() - timeStart)
    print('All jobs submitted. Time taken: ' + timeTaken + '.')