Пример #1
0
    def start_minimization(self, which_min):
        job = {}

        saddle_path = os.path.join(config.path_incomplete, self.finished_saddle_name)

        mode_file = open(os.path.join(saddle_path, "mode.dat"))
        mode = io.load_mode(mode_file)
        mode_file.close()

        reactant_file = open(os.path.join(saddle_path, "saddle.con"))
        reactant = io.loadcon(reactant_file)
        reactant_file.close()

        if which_min == "min2":
            mode = -mode

        reactant.r += config.process_search_minimization_offset*mode

        reactIO = StringIO.StringIO()
        io.savecon(reactIO, reactant)
        job['pos.con'] = reactIO

        ini_changes = [ ('Main', 'job', 'minimization') ]
        job['config.ini'] = io.modify_config(config.config_path, ini_changes)

        return job
Пример #2
0
    def start_minimization(self, which_min):
        job = {}

        saddle_path = os.path.join(config.path_incomplete,
                                   self.finished_saddle_name)

        mode_file = open(os.path.join(saddle_path, "mode.dat"))
        mode = io.load_mode(mode_file)
        mode_file.close()

        reactant_file = open(os.path.join(saddle_path, "saddle.con"))
        reactant = io.loadcon(reactant_file)
        reactant_file.close()

        if which_min == "min2":
            mode = -mode

        reactant.r += config.process_search_minimization_offset * mode

        reactIO = StringIO.StringIO()
        io.savecon(reactIO, reactant)
        job['pos.con'] = reactIO

        ini_changes = [('Main', 'job', 'minimization')]
        job['config.ini'] = io.modify_config(config.config_path, ini_changes)

        return job
Пример #3
0
    def make_suggestion(self):
        """ Makes a saddle suggestion and returns True.
            If no more saddle suggestions are possible
            (end of process table has been reached), returns False. """
        # If we've gone through all the possible processes
        if self.process_number >= self.num_procs:
            self.write_recycling_metadata()
            return None, None

        # Make a fresh copy of the "saddle" we're going to send,
        # based on the current reactant.
        saddle = self.curr_reactant.copy()
        # Determine what happens in the reference state saddle
        # for the current process number.
        process_saddle = self.ref_state.get_process_saddle(self.process_number)
        process_mode = self.ref_state.get_process_mode(self.process_number)

        # Now, for all the things that did *not* move getting to this state,
        # suggest this particular process's position to them.

        for i in self.unmoved:
            saddle.r[i] = process_saddle.r[i]
            self.mode[i] = process_mode[i]

        # And, for all the things that *did* move getting to this state,
        # suggest the *motion* that they had available before to the
        # current position they're in.

        for i in self.moved:
            movement = process_saddle.r[i] - self.ref_reactant.r[i]
            saddle.r[i] += movement
            self.mode[i] = process_mode[i]

        # Save suggestions?
        if self.save:
            save_path = os.path.join(self.current_state.path,
                                     "saddle_suggestions")
            if not os.path.isdir(save_path):
                os.mkdir(save_path)
            fo = open(os.path.join(save_path, "proc_%d" % self.process_number),
                      "w")
            io.savecon(fo, saddle)
            fo.close()

        # Make a note of the fact that we've tried to recycle another saddle.
        self.process_number += 1
        self.write_recycling_metadata()
        # Note: Uncomment the final return values to also return the list of indices of atoms
        # which are not in the hole and in the hole.  No change should need to be made to the
        # line in akmc.py which calls this function (unless akmc.py wants them as well).
        return saddle.copy(), self.mode.copy()
Пример #4
0
    def make_suggestion(self):
        """ Makes a saddle suggestion and returns True.
            If no more saddle suggestions are possible
            (end of process table has been reached), returns False. """
        # If we've gone through all the possible processes
        if self.process_number >= self.num_procs:
            self.write_recycling_metadata()
            return None, None

        # Make a fresh copy of the "saddle" we're going to send,
        # based on the current reactant.
        saddle = self.curr_reactant.copy()
        # Determine what happens in the reference state saddle
        # for the current process number.
        process_saddle = self.ref_state.get_process_saddle(self.process_number)
        process_mode = self.ref_state.get_process_mode(self.process_number)

        # Now, for all the things that did *not* move getting to this state,
        # suggest this particular process's position to them.

        for i in self.unmoved:
            saddle.r[i] = process_saddle.r[i]
            self.mode[i] = process_mode[i]

        # And, for all the things that *did* move getting to this state,
        # suggest the *motion* that they had available before to the
        # current position they're in.

        for i in self.moved:
            movement = process_saddle.r[i] - self.ref_reactant.r[i]
            saddle.r[i] += movement
            self.mode[i] = process_mode[i]

        # Save suggestions?
        if self.save:
            save_path = os.path.join(self.current_state.path, "saddle_suggestions")
            if not os.path.isdir(save_path):
                os.mkdir(save_path)
            fo = open(os.path.join(save_path, "proc_%d" %self.process_number), "w")
            io.savecon(fo, saddle)
            fo.close()

        # Make a note of the fact that we've tried to recycle another saddle.
        self.process_number += 1
        self.write_recycling_metadata()
        # Note: Uncomment the final return values to also return the list of indices of atoms
        # which are not in the hole and in the hole.  No change should need to be made to the
        # line in akmc.py which calls this function (unless akmc.py wants them as well).
        return saddle.copy(), self.mode.copy()
Пример #5
0
    def start_search(self):
        job = {}

        dispIO = StringIO.StringIO()
        io.savecon(dispIO, self.displacement)
        job['displacement.con'] = dispIO

        modeIO = StringIO.StringIO()
        io.save_mode(modeIO, self.mode)
        job['direction.dat'] = modeIO

        reactIO = StringIO.StringIO()
        io.savecon(reactIO, self.reactant)
        job['pos.con'] = reactIO

        ini_changes = [ ('Main', 'job', 'saddle_search') ]
        job['config.ini'] = io.modify_config(config.config_path, ini_changes)

        return job
Пример #6
0
    def start_search(self):
        job = {}

        dispIO = StringIO.StringIO()
        io.savecon(dispIO, self.displacement)
        job['displacement.con'] = dispIO

        modeIO = StringIO.StringIO()
        io.save_mode(modeIO, self.mode)
        job['direction.dat'] = modeIO

        reactIO = StringIO.StringIO()
        io.savecon(reactIO, self.reactant)
        job['pos.con'] = reactIO

        ini_changes = [('Main', 'job', 'saddle_search')]
        job['config.ini'] = io.modify_config(config.config_path, ini_changes)

        return job
Пример #7
0
def make_searches(comm, current_state, wuid):
    reactant = current_state.get_reactant()
    #XXX:what if the user changes the bundle size?
    num_in_buffer = comm.get_queue_size() * config.comm_job_bundle_size
    logger.info("Queue contains %i searches" % num_in_buffer)
    num_to_make = max(config.comm_job_buffer_size - num_in_buffer, 0)
    logger.info("Making %i searches" % num_to_make)

    if num_to_make == 0:
        return wuid

    searches = []

    invariants = {}

    reactIO = StringIO()
    io.savecon(reactIO, reactant)

    # Merge potential files into invariants
    #XXX: Should this be in our "science" maybe the communicator should
    #     handle this.
    invariants = dict(invariants, **io.load_potfiles(config.path_pot))

    searches = []
    for i in range(num_to_make):
        search = {}
        search['id'] = "%d_%d" % (current_state.number, wuid)
        search['pos.con'] = reactIO
        ini_changes = [
            ('Main', 'job', 'parallel_replica'),
            ('Main', 'random_seed', str(int(numpy.random.random() * 10**9))),
        ]
        search['config.ini'] = io.modify_config(config.config_path,
                                                ini_changes)
        searches.append(search)
        wuid += 1

    comm.submit_jobs(searches, invariants)
    logger.info("Created " + str(num_to_make) + " searches")
    return wuid
Пример #8
0
def make_searches(comm, current_state, wuid):
    reactant = current_state.get_reactant()
    #XXX:what if the user changes the bundle size?
    num_in_buffer = comm.get_queue_size()*config.comm_job_bundle_size
    logger.info("Queue contains %i searches" % num_in_buffer)
    num_to_make = max(config.comm_job_buffer_size - num_in_buffer, 0)
    logger.info("Making %i searches" % num_to_make)
    
    if num_to_make == 0:
        return wuid

    searches = []

    invariants = {}

    reactIO = StringIO()
    io.savecon(reactIO, reactant)

    # Merge potential files into invariants
    #XXX: Should this be in our "science" maybe the communicator should
    #     handle this.
    invariants = dict(invariants, **io.load_potfiles(config.path_pot))

    searches = []
    for i in range(num_to_make):
        search = {}
        search['id'] = "%d_%d" % (current_state.number, wuid)
        search['pos.con']  = reactIO
        ini_changes = [
                        ('Main', 'job', 'parallel_replica'),
                        ('Main', 'random_seed',
                            str(int(numpy.random.random()*10**9))),
                      ]
        search['config.ini'] = io.modify_config(config.config_path, ini_changes)
        searches.append(search)
        wuid += 1

    comm.submit_jobs(searches, invariants)
    logger.info("Created " + str(num_to_make) + " searches")
    return wuid
Пример #9
0
    def make_jobs(self):
        #XXX:what if the user changes the bundle size?
        num_in_buffer = self.comm.get_queue_size()*config.comm_job_bundle_size 
        logger.info("Queue contains %i searches" % num_in_buffer)
        num_to_make = max(config.comm_job_buffer_size - num_in_buffer, 0)
        logger.info("Making %i process searches" % num_to_make)

        if num_to_make == 0:
            return

        searches = []

        invariants = {}

        reactIO = StringIO.StringIO()
        io.savecon(reactIO, self.reactant)
        file_permission = os.stat("pos.con").st_mode
        invariants['pos.con'] = (reactIO, file_permission)

        t1 = time()
        if config.saddle_method == 'dynamics' and \
                config.recycling_on and \
                config.disp_moved_only and \
                self.state.number != 0:

            moved_atoms = self.recycler.process_atoms
            mass_weights = self.reactant.mass.copy()
            mass_weights *= config.recycling_mass_weight_factor

            for i in range(len(self.reactant)):
                if i in moved_atoms:
                    mass_weights[i] = self.reactant.mass[i]

            weightsIO = StringIO.StringIO()
            numpy.savetxt(weightsIO, mass_weights)
            file_permission = os.stat("masses.dat").st_mode
            invariants['masses.dat'] = (weightsIO, file_permission)

        # Merge potential files into invariants
        invariants = dict(invariants, **io.load_potfiles(config.path_pot))

        for i in range(num_to_make):
            search = {}
            # The search dictionary contains the following key-value pairs:
            # id - CurrentState_WUID
            # displacement - an atoms object containing the point the saddle search will start at
            # mode - an Nx3 numpy array containing the initial mode 
            search['id'] = "%d_%d" % (self.state.number, self.wuid)
            displacement, mode, disp_type = self.generate_displacement()
            self.job_table.add_row( {'state':self.state.number,
                                     'wuid':self.wuid,
                                     'type':disp_type } )

            ini_changes = [ ('Main', 'job', 'process_search'),
                            ('Main', 'random_seed',
                                str(int(numpy.random.random()*10**9))),
                          ]
            # if we are recycling a saddle, but using "dynamics saddle search" we need
            # to switch to min_mode searches
            if config.saddle_method == 'dynamics' and disp_type != 'dynamics':
                ini_changes.append( ('Saddle Search', 'method', 'min_mode') )

            search['config.ini'] = io.modify_config(config.config_path, ini_changes)

            if displacement:
                dispIO = StringIO.StringIO()
                io.savecon(dispIO, displacement)
                search['displacement.con'] = dispIO
                modeIO = StringIO.StringIO()
                io.save_mode(modeIO, mode)
                search['direction.dat'] = modeIO

            searches.append(search) 
            self.wuid += 1
            # eager write
            self.save_wuid()

        if config.recycling_on and self.nrecycled > 0:
            logger.info("Recycled %i saddles" % self.nrecycled)

        try:
            self.comm.submit_jobs(searches, invariants)
            t2 = time()
            logger.info( "Created " + str(len(searches)) + " searches") 
            logger.debug( "Created " + str(num_to_make/(t2-t1)) + " searches per second")
        except:
            logger.exception("Failed to submit searches")
        self.job_table.write()
Пример #10
0
    def make_jobs(self):
        #XXX:what if the user changes the bundle size?
        num_in_buffer = self.comm.get_queue_size(
        ) * config.comm_job_bundle_size
        logger.info("Queue contains %i searches" % num_in_buffer)
        num_to_make = max(config.comm_job_buffer_size - num_in_buffer, 0)
        logger.info("Making %i process searches" % num_to_make)

        if num_to_make == 0:
            return

        searches = []

        invariants = {}

        reactIO = StringIO.StringIO()
        io.savecon(reactIO, self.reactant)
        file_permission = os.stat("pos.con").st_mode
        invariants['pos.con'] = (reactIO, file_permission)

        t1 = time()
        if config.saddle_method == 'dynamics' and \
                config.recycling_on and \
                config.disp_moved_only and \
                self.state.number != 0:

            moved_atoms = self.recycler.process_atoms
            mass_weights = self.reactant.mass.copy()
            mass_weights *= config.recycling_mass_weight_factor

            for i in range(len(self.reactant)):
                if i in moved_atoms:
                    mass_weights[i] = self.reactant.mass[i]

            weightsIO = StringIO.StringIO()
            numpy.savetxt(weightsIO, mass_weights)
            file_permission = os.stat("masses.dat").st_mode
            invariants['masses.dat'] = (weightsIO, file_permission)

        # Merge potential files into invariants
        invariants = dict(invariants, **io.load_potfiles(config.path_pot))

        for i in range(num_to_make):
            search = {}
            # The search dictionary contains the following key-value pairs:
            # id - CurrentState_WUID
            # displacement - an atoms object containing the point the saddle search will start at
            # mode - an Nx3 numpy array containing the initial mode
            search['id'] = "%d_%d" % (self.state.number, self.wuid)
            displacement, mode, disp_type = self.generate_displacement()
            self.job_table.add_row({
                'state': self.state.number,
                'wuid': self.wuid,
                'type': disp_type
            })

            ini_changes = [
                ('Main', 'job', 'process_search'),
                ('Main', 'random_seed',
                 str(int(numpy.random.random() * 10**9))),
            ]
            # if we are recycling a saddle, but using "dynamics saddle search" we need
            # to switch to min_mode searches
            if config.saddle_method == 'dynamics' and disp_type != 'dynamics':
                ini_changes.append(('Saddle Search', 'method', 'min_mode'))

            search['config.ini'] = io.modify_config(config.config_path,
                                                    ini_changes)

            if displacement:
                dispIO = StringIO.StringIO()
                io.savecon(dispIO, displacement)
                search['displacement.con'] = dispIO
                modeIO = StringIO.StringIO()
                io.save_mode(modeIO, mode)
                search['direction.dat'] = modeIO

            searches.append(search)
            self.wuid += 1
            # eager write
            self.save_wuid()

        if config.recycling_on and self.nrecycled > 0:
            logger.info("Recycled %i saddles" % self.nrecycled)

        try:
            self.comm.submit_jobs(searches, invariants)
            t2 = time()
            logger.info("Created " + str(len(searches)) + " searches")
            logger.debug("Created " + str(num_to_make / (t2 - t1)) +
                         " searches per second")
        except:
            logger.exception("Failed to submit searches")
        self.job_table.write()
Пример #11
0
    if 'bcc' in sys.argv:
        ids = atoms.cnat(p, 3.5)
        for i in range(len(ids)):
            if ids[i] == 5:
                rejects.append(i)

    if 'a15' in sys.argv:
        ids = atoms.cnat(p, 3.5)
        for i in range(len(ids)):
            if ids[i] in [1, 2]:
                rejects.append(i)

    rejects = list(set(rejects))

    newp = atoms.Atoms(len(p) - len(rejects))
    newp.box = p.box
    index = 0
    for i in range(len(p)):
        if i not in rejects:
            newp.r[index] = p.r[i]
            newp.free[index] = p.free[i]
            newp.names[index] = p.names[i]
            newp.mass[index] = p.mass[i]
            index += 1
    filtered.append(newp)

io.savecon(sys.argv[2], filtered[0], 'w')

for p in filtered[1:]:
    io.savecon(sys.argv[2], p, 'a')