예제 #1
0
 def get_magmom(self):
     try:
         d_electrons = d_filling[self.element]
     except KeyError:
         raise Errors.ElementNotRecognizedError(self.element)
     if d_electrons == 0:
         num_electrons = 0
     else:
         num_electrons = d_electrons - self.charge
     field = CrystalField(self.system, self.spin)
     return field.get_moment(num_electrons)
예제 #2
0
def parsePOSCAR(path):
    try:
        f = open(path, 'r')
        # read the first line in POSCAR file
        first_line = f.readline()
        # get the first element; this will be used to detect the lines that give
        # information about elements/ the # of occurences in the structure
        first_elem = re.sub(r'[^a-zA-Z]', '', first_line.split(' ')[0])
        second_elem = re.sub(r'[^a-zA-Z]', '', first_line.split(' ')[1])
        # get information about the order of elements and their # of occurences in the structure
        element_text = ''
        multiplicity_text = ''
        # read each line in the file until the lines containing multiplicity information are found
        while True:
            text = f.readline()
            # if the first element pops up, this means we have found the correct line
            if re.search('%s' % (first_elem), text) and re.search(
                    '%s' % (second_elem), text):
                element_text = text
                multiplicity_text = f.readline()
                break
            if not text:
                raise Errors.MultiplicitySearchError
        # get element order based on how elements are orderd in the POSCAR file
        element_order = [element for element in element_text.split()]
        print(element_order)
        for element in element_order:
            if not element in d_filling:
                raise Errors.ElementNotRecognizedError(element)
        # get the muliplicities, which is the line underneath the elements line
        element_multiplicity = [
            int(multiplicity) for multiplicity in multiplicity_text.split()
        ]
        # store both information in a nested list
        element_params = [[
            order, multiplicity
        ] for order, multiplicity in zip(element_order, element_multiplicity)]
        return element_params
    except Exception as e:
        raise Errors.ParsePoscarError(e)