Пример #1
0
    def move_random(self, entry_id, factor=0.2, in_place=False, kind='move'):
        """
        Change the magnetic orientation randomly for all the atoms considered magnetic 'mag_atoms'
        The 'factor' argument scales the intensite of the movement.

        :param entry_id:
        :param factor:
        :param in_place:
        :param kind:
        :return:
        """
        entry = self.get_entry(entry_id, {'properties.magmom': 1})
        # Magnetic Momenta are stored in spherical coordinates
        magmom_xyz = spherical_to_cartesian(entry['properties']['magmom'])
        # Randomly disturbed using the factor
        magmom_xyz += factor * np.random.random(
            (self.structure.natom, 3)) - factor / 2
        # Reconverting to spherical coordinates
        magmom_new = cartesian_to_spherical(magmom_xyz)
        # Resetting magnitudes
        for i in range(len(magmom_xyz)):
            if magmom_xyz[i][0] > 0.0:
                magmom_new[i, 0] = self.magmom_magnitude
            else:
                magmom_new[i, 0] = 0.0

        properties = {
            'magmom': list(magmom_new.flatten()),
            'energy': self.debug_evaluation(magmom_new)
        }

        if in_place:
            return self.update_properties(entry_id, new_properties=properties)
        else:
            return self.new_entry(magmom_new, active=False)
Пример #2
0
    def move(self, entry_id, entry_jd, factor=0.2, in_place=False):

#FAKE FACTOR
#        factor=1.0
        magmom_new_xyz = np.zeros((self.structure.natom, 3)) 
        entry = self.get_entry(entry_id, {'properties.magmom': 1})
        magmom_i = np.array(entry['properties']['magmom']).reshape((-1, 3))
        magmom_ixyz = spherical_to_cartesian(magmom_i)
        entry = self.get_entry(entry_jd, {'properties.magmom': 1})
        magmom_j = np.array(entry['properties']['magmom']).reshape((-1, 3))
        magmom_jxyz = spherical_to_cartesian(magmom_j)

#        print('Rotating %s towards %s with factor %f' % (entry_id, entry_jd, factor))
#        print('Origin:\n %s ' % magmom_i[self.mag_atoms])
#        print('Destin:\n %s ' % magmom_j[self.mag_atoms])
        for i in self.mag_atoms:
            #print('Atom %d' % i)
            if magmom_i[i][0] > 0 and magmom_j[i][0] > 0:         
                magmom_new_xyz[i] = rotate_towards_axis(magmom_ixyz[i], magmom_jxyz[i],
                                                                                   fraction=factor)
                #print('Final magmom Cartesian : %d     %s' % (i,magmom_new_xyz[i]))

        magmom_new = cartesian_to_spherical(magmom_new_xyz)
#        print('Final spherical:\n %s' % magmom_new[self.mag_atoms])
        magmom_new[:, 0] = self.magmom_magnitude

        properties = {'magmom': list(magmom_new.flatten()), 'energy': self.fake_evaluation(magmom_new)}

        if in_place:
            self.update_properties(entry_id, new_properties=properties)
            return entry_id
        else:
            return self.new_entry(magmom_new, active=False)
    def move_random(self, entry_id, factor=0.2, in_place=False, kind='move'):
        """
        Change the magnetic orientation randomly for all the atoms considered magnetic 'mag_atoms'
        The 'factor' argument scales the intensite of the movement.

        :param entry_id:
        :param factor:
        :param in_place:
        :param kind:
        :return:
        """
        entry = self.get_entry(entry_id, {'properties.magmom': 1})
        # Magnetic Momenta are stored in spherical coordinates
        magmom_xyz = spherical_to_cartesian(entry['properties']['magmom'])
        # Randomly disturbed using the factor
        magmom_xyz += factor * np.random.random((self.structure.natom, 3)) - factor / 2
        # Reconverting to spherical coordinates
        magmom_new = cartesian_to_spherical(magmom_xyz)
        # Resetting magnitudes
        for i in range(len(magmom_xyz)):
            if magmom_xyz[i][0] > 0.0:
                magmom_new[i, 0] = self.magmom_magnitude
            else:
                magmom_new[i, 0] = 0.0

        properties = {'magmom': list(magmom_new.flatten()), 'energy': self.debug_evaluation(magmom_new)}

        if in_place:
            return self.update_properties(entry_id, new_properties=properties)
        else:
            return self.new_entry(magmom_new, active=False)
Пример #4
0
    def move(self, entry_id, entry_jd, factor=0.2, in_place=False):
        """
        Move the magnetic moments from one candidate in the direction of another.

        :param entry_id: Source candidate, this one will be moved
        :param entry_jd: Destination candidate, this one is not moved.
        :param factor: (float) a value in range [0,1] 0 being the source, 1 the destination
        :param in_place: (bool) if true the new magnetic moments replace those in entry_id
        :return:
        """
        magmom_new_xyz = np.zeros((self.structure.natom, 3))
        entry = self.get_entry(entry_id, {'properties.magmom': 1})
        magmom_i = np.array(entry['properties']['magmom']).reshape((-1, 3))
        magmom_ixyz = spherical_to_cartesian(magmom_i)
        entry = self.get_entry(entry_jd, {'properties.magmom': 1})
        magmom_j = np.array(entry['properties']['magmom']).reshape((-1, 3))
        magmom_jxyz = spherical_to_cartesian(magmom_j)

        for i in self.mag_atoms:
            # print('Atom %d' % i)
            if magmom_i[i][0] > 0 and magmom_j[i][0] > 0:
                magmom_new_xyz[i] = rotate_towards_axis(magmom_ixyz[i],
                                                        magmom_jxyz[i],
                                                        fraction=factor)
                # print('Final magmom Cartesian : %d     %s' % (i,magmom_new_xyz[i]))

        magmom_new = cartesian_to_spherical(magmom_new_xyz)

        magmom_new[:, 0] = self.magmom_magnitude
        for i in range(self.structure.natom):
            if i not in self.mag_atoms:
                magmom_new[i, :] = 0.0

        properties = {
            'magmom': list(magmom_new.flatten()),
            'energy': self.debug_evaluation(magmom_new)
        }

        if in_place:
            self.update_properties(entry_id, new_properties=properties)
            return entry_id
        else:
            return self.new_entry(magmom_new, active=False)
Пример #5
0
    def move_random(self, entry_id, factor=0.2, in_place=False, kind='move'):

        entry = self.get_entry(entry_id, {'properties.magmom': 1})
        # Magnetic Momenta are stored in spherical coordinates
        magmom_i = spherical_to_cartesian(entry['properties']['magmom'])
        # Converted into cartesians
        magmom_xyz = spherical_to_cartesian(magmom_i)
        # Randomly disturbed using the factor
        magmom_xyz += factor * np.random.rand((self.structure.natom, 3)) - factor / 2
        # Reconverting to spherical coordinates
        magmom_new = cartesian_to_spherical(magmom_xyz)
        # Resetting magnitudes
        magmom_new[:, 0] = self.magmom_magnitude
        properties = {'magmom': magmom_new}

        if in_place:
            return self.update_properties(entry_id, new_properties=properties)
        else:
            return self.new_entry(magmom_new, active=False)
Пример #6
0
    def move(self, entry_id, entry_jd, factor=0.2, in_place=False):
        """
        Move the magnetic moments from one candidate in the direction of another.

        :param entry_id:
        :param entry_jd:
        :param factor:
        :param in_place:
        :return:
        """
        magmom_new_xyz = np.zeros((self.structure.natom, 3)) 
        entry = self.get_entry(entry_id, {'properties.magmom': 1})
        magmom_i = np.array(entry['properties']['magmom']).reshape((-1, 3))
        magmom_ixyz = spherical_to_cartesian(magmom_i)
        entry = self.get_entry(entry_jd, {'properties.magmom': 1})
        magmom_j = np.array(entry['properties']['magmom']).reshape((-1, 3))
        magmom_jxyz = spherical_to_cartesian(magmom_j)

#        print('Rotating %s towards %s with factor %f' % (entry_id, entry_jd, factor))
#        print('Origin:\n %s ' % magmom_i[self.mag_atoms])
#        print('Destin:\n %s ' % magmom_j[self.mag_atoms])
        for i in self.mag_atoms:
            #print('Atom %d' % i)
            if magmom_i[i][0] > 0 and magmom_j[i][0] > 0:         
                magmom_new_xyz[i] = rotate_towards_axis(magmom_ixyz[i], magmom_jxyz[i],
                                                                                   fraction=factor)
                #print('Final magmom Cartesian : %d     %s' % (i,magmom_new_xyz[i]))

        magmom_new = cartesian_to_spherical(magmom_new_xyz)
#        print('Final spherical:\n %s' % magmom_new[self.mag_atoms])

        magmom_new[:, 0] = self.magmom_magnitude
        for i in range(self.structure.natom):
            if i not in self.mag_atoms:
                magmom_new[i, :] = 0.0

        properties = {'magmom': list(magmom_new.flatten()), 'energy': self.debug_evaluation(magmom_new)}

        if in_place:
            self.update_properties(entry_id, new_properties=properties)
            return entry_id
        else:
            return self.new_entry(magmom_new, active=False)
Пример #7
0
    def move(self, entry_id, entry_jd, factor=0.2, in_place=False):
        magmom_new_xyz = np.zeros((self.structure.natom, 3))
        entry = self.get_entry(entry_id, {'properties.magmom': 1})
        magmom_i = np.array(entry['properties']['magmom']).reshape((-1, 3))
        magmom_ixyz = spherical_to_cartesian(magmom_i)
        entry = self.get_entry(entry_id, {'properties.magmom': 1})
        magmom_j = np.array(entry['properties']['magmom']).reshape((-1, 3))
        magmom_jxyz = spherical_to_cartesian(magmom_j)

        for i in range(self.structure.natom):
            if magmom_ixyz[i][0] > 0 and magmom_jxyz[i][0] > 0:
                magmom_new_xyz[i] = rotate_towards_axis(magmom_ixyz[i], magmom_jxyz[i],
                                                                                   fraction=factor)

        magmom_new = cartesian_to_spherical(magmom_new_xyz)
        magmom_new[:, 0] = self.magmom_magnitude
        properties = {'magmom': magmom_new}

        if in_place:
            return self.update_properties(entry_id, new_properties=properties)
        else:
            return self.new_entry(magmom_new, active=False)
    def move(self, entry_id, entry_jd, factor=0.2, in_place=False):
        """
        Move the magnetic moments from one candidate in the direction of another.

        :param entry_id: Source candidate, this one will be moved
        :param entry_jd: Destination candidate, this one is not moved.
        :param factor: (float) a value in range [0,1] 0 being the source, 1 the destination
        :param in_place: (bool) if true the new magnetic moments replace those in entry_id
        :return:
        """
        magmom_new_xyz = np.zeros((self.structure.natom, 3))
        entry = self.get_entry(entry_id, {'properties.magmom': 1})
        magmom_i = np.array(entry['properties']['magmom']).reshape((-1, 3))
        magmom_ixyz = spherical_to_cartesian(magmom_i)
        entry = self.get_entry(entry_jd, {'properties.magmom': 1})
        magmom_j = np.array(entry['properties']['magmom']).reshape((-1, 3))
        magmom_jxyz = spherical_to_cartesian(magmom_j)

        for i in self.mag_atoms:
            # print('Atom %d' % i)
            if magmom_i[i][0] > 0 and magmom_j[i][0] > 0:
                magmom_new_xyz[i] = rotate_towards_axis(magmom_ixyz[i], magmom_jxyz[i], fraction=factor)
                # print('Final magmom Cartesian : %d     %s' % (i,magmom_new_xyz[i]))

        magmom_new = cartesian_to_spherical(magmom_new_xyz)

        magmom_new[:, 0] = self.magmom_magnitude
        for i in range(self.structure.natom):
            if i not in self.mag_atoms:
                magmom_new[i, :] = 0.0

        properties = {'magmom': list(magmom_new.flatten()), 'energy': self.debug_evaluation(magmom_new)}

        if in_place:
            self.update_properties(entry_id, new_properties=properties)
            return entry_id
        else:
            return self.new_entry(magmom_new, active=False)
Пример #9
0
    def move(self, entry_id, entry_jd, factor=0.2, in_place=False):

        #FAKE FACTOR
        #        factor=1.0
        magmom_new_xyz = np.zeros((self.structure.natom, 3))
        entry = self.get_entry(entry_id, {'properties.magmom': 1})
        magmom_i = np.array(entry['properties']['magmom']).reshape((-1, 3))
        magmom_ixyz = spherical_to_cartesian(magmom_i)
        entry = self.get_entry(entry_jd, {'properties.magmom': 1})
        magmom_j = np.array(entry['properties']['magmom']).reshape((-1, 3))
        magmom_jxyz = spherical_to_cartesian(magmom_j)

        #        print('Rotating %s towards %s with factor %f' % (entry_id, entry_jd, factor))
        #        print('Origin:\n %s ' % magmom_i[self.mag_atoms])
        #        print('Destin:\n %s ' % magmom_j[self.mag_atoms])
        for i in self.mag_atoms:
            #print('Atom %d' % i)
            if magmom_i[i][0] > 0 and magmom_j[i][0] > 0:
                magmom_new_xyz[i] = rotate_towards_axis(magmom_ixyz[i],
                                                        magmom_jxyz[i],
                                                        fraction=factor)
                #print('Final magmom Cartesian : %d     %s' % (i,magmom_new_xyz[i]))

        magmom_new = cartesian_to_spherical(magmom_new_xyz)
        #        print('Final spherical:\n %s' % magmom_new[self.mag_atoms])
        magmom_new[:, 0] = self.magmom_magnitude

        properties = {
            'magmom': list(magmom_new.flatten()),
            'energy': self.fake_evaluation(magmom_new)
        }

        if in_place:
            self.update_properties(entry_id, new_properties=properties)
            return entry_id
        else:
            return self.new_entry(magmom_new, active=False)