def _process_typedef(targetdb, typechar, line): """ Process the TYPE_DEFINITION command. """ # GES A_P_D BCC_A2 MAGNETIC -1 0.4 tokens = line.replace(',', '').split() if len(tokens) < 4: return keyword = expand_keyword(['DISORDERED_PART', 'MAGNETIC'], tokens[3].upper())[0] if len(keyword) == 0: raise ValueError('Unknown keyword: {}'.format(tokens[3])) if keyword == 'MAGNETIC': # magnetic model (IHJ model assumed by default) targetdb.tdbtypedefs[typechar] = { 'ihj_magnetic':[float(tokens[4]), float(tokens[5])] } # GES A_P_D L12_FCC DIS_PART FCC_A1 if keyword == 'DISORDERED_PART': # order-disorder model targetdb.tdbtypedefs[typechar] = { 'disordered_phase': tokens[4].upper(), 'ordered_phase': tokens[2].upper() } if tokens[2].upper() in targetdb.phases: # Since TDB files do not enforce any kind of ordering # on the specification of ordered and disordered phases, # we need to handle the case of when either phase is specified # first. In this case, we imagine the ordered phase is # specified first. If the disordered phase is specified # first, we will have to catch it in _process_phase(). targetdb.phases[tokens[2].upper()].model_hints.update( targetdb.tdbtypedefs[typechar] )
def parseImpl(self, instring, loc, doActions=True): # Find the end of the keyword by searching for an end character start = loc endchars = ' ():,' loc = -1 for charx in endchars: locx = instring.find(charx, start) if locx != -1: # match the end-character closest to the start character if loc != -1: loc = min(loc, locx) else: loc = locx # if no end character found, just match the whole thing if loc == -1: loc = len(instring) try: res = expand_keyword([self.match], instring[start:loc]) if len(res) > 1: self.errmsg = '{0!r} is ambiguous: matches {1}' \ .format(instring[start:loc], res) raise ParseException(instring, loc, self.errmsg, self) # res[0] is the unambiguous expanded keyword # in principle, res[0] == self.match return loc, res[0] except ValueError: pass raise ParseException(instring, loc, self.errmsg, self)
def _process_typedef(targetdb, typechar, line): """ Process the TYPE_DEFINITION command. """ # GES A_P_D BCC_A2 MAGNETIC -1 0.4 tokens = line.replace(',', '').split() if len(tokens) < 4: return keyword = expand_keyword(['DISORDERED_PART', 'MAGNETIC'], tokens[3].upper())[0] if len(keyword) == 0: raise ValueError('Unknown keyword: {}'.format(tokens[3])) if keyword == 'MAGNETIC': # magnetic model (IHJ model assumed by default) targetdb.tdbtypedefs[typechar] = { 'ihj_magnetic': [float(tokens[4]), float(tokens[5])] } # GES A_P_D L12_FCC DIS_PART FCC_A1 if keyword == 'DISORDERED_PART': # order-disorder model targetdb.tdbtypedefs[typechar] = { 'disordered_phase': tokens[4].upper(), 'ordered_phase': tokens[2].upper() } if tokens[2].upper() in targetdb.phases: # Since TDB files do not enforce any kind of ordering # on the specification of ordered and disordered phases, # we need to handle the case of when either phase is specified # first. In this case, we imagine the ordered phase is # specified first. If the disordered phase is specified # first, we will have to catch it in _process_phase(). targetdb.phases[tokens[2].upper()].model_hints.update( targetdb.tdbtypedefs[typechar])
def _process_typedef(targetdb, typechar, line): """ Process a TYPE_DEFINITION command. Assumes all phases are entered into the database already and that the database defines _typechar_map, which defines a map of typechar to the phases that use it. Any phases that in the typechar dict for this will have the model_hints updated based on this type definition, regardless of which phase names may be defined in this TYPE_DEF line. """ matching_phases = targetdb._typechar_map[typechar] del targetdb._typechar_map[typechar] # GES A_P_D BCC_A2 MAGNETIC -1 0.4 tokens = line.replace(',', '').split() if len(tokens) < 4: return keyword = expand_keyword(['DISORDERED_PART', 'MAGNETIC'], tokens[3].upper())[0] if len(keyword) == 0: raise ValueError('Unknown type definition keyword: {}'.format( tokens[3])) if len(matching_phases) == 0: warnings.warn( f"The type definition character `{typechar}` in `TYPE_DEFINITION {typechar} {line}` is not used by any phase." ) if keyword == 'MAGNETIC': # Magnetic model, both IHJ and Xiong models use these model hints when # constructing Model instances, despite being prefixed `ihj_magnetic_` model_hints = { 'ihj_magnetic_afm_factor': float(tokens[4]), 'ihj_magnetic_structure_factor': float(tokens[5]) } for phase_name in matching_phases: targetdb.phases[phase_name].model_hints.update(model_hints) # GES A_P_D L12_FCC DIS_PART FCC_A1 if keyword == 'DISORDERED_PART': # order-disorder model: since we need to add model_hints to both the # ordered and disorderd phase, we special case to update the phase # names defined by the TYPE_DEF, rather than the updating the phases # with matching typechars. ordered_phase = tokens[2].upper() disordered_phase = tokens[4].upper() hint = { 'ordered_phase': ordered_phase, 'disordered_phase': disordered_phase, } if ordered_phase in targetdb.phases: targetdb.phases[ordered_phase].model_hints.update(hint) else: raise ValueError( f"The {ordered_phase} phase is not in the database, but is defined by: `TYPE_DEFINTION {typechar} {line}`" ) if disordered_phase in targetdb.phases: targetdb.phases[disordered_phase].model_hints.update(hint) else: raise ValueError( f"The {disordered_phase} phase is not in the database, but is defined by: `TYPE_DEFINTION {typechar} {line}`" )