dara.result module#

The parser for the result from the refinement.

pydantic model DiaResult[source]#

Bases: BaseModel

Refinement result parsed from the .dia file. Mainly some x-y data for plotting.

Show JSON schema
{
   "title": "DiaResult",
   "description": "Refinement result parsed from the .dia file. Mainly some x-y data for plotting.",
   "type": "object",
   "properties": {
      "x": {
         "items": {
            "type": "number"
         },
         "title": "X",
         "type": "array"
      },
      "y_obs": {
         "items": {
            "type": "number"
         },
         "title": "Y Obs",
         "type": "array"
      },
      "y_calc": {
         "items": {
            "type": "number"
         },
         "title": "Y Calc",
         "type": "array"
      },
      "y_bkg": {
         "items": {
            "type": "number"
         },
         "title": "Y Bkg",
         "type": "array"
      },
      "structs": {
         "additionalProperties": {
            "items": {
               "type": "number"
            },
            "type": "array"
         },
         "title": "Structs",
         "type": "object"
      }
   },
   "required": [
      "x",
      "y_obs",
      "y_calc",
      "y_bkg",
      "structs"
   ]
}

Fields:
field structs: dict[str, list[float]] [Required]#
field x: list[float] [Required]#
field y_bkg: list[float] [Required]#
field y_calc: list[float] [Required]#
field y_obs: list[float] [Required]#
pydantic model LstResult[source]#

Bases: BaseModel

Refinement result parsed from the .lst file.

Show JSON schema
{
   "title": "LstResult",
   "description": "Refinement result parsed from the .lst file.",
   "type": "object",
   "properties": {
      "raw_lst": {
         "title": "Raw Lst",
         "type": "string"
      },
      "pattern_name": {
         "title": "Pattern Name",
         "type": "string"
      },
      "num_steps": {
         "title": "Num Steps",
         "type": "integer"
      },
      "Rp": {
         "title": "Rp",
         "type": "number"
      },
      "Rpb": {
         "title": "Rpb",
         "type": "number"
      },
      "R": {
         "title": "R",
         "type": "number"
      },
      "Rwp": {
         "title": "Rwp",
         "type": "number"
      },
      "Rexp": {
         "title": "Rexp",
         "type": "number"
      },
      "d": {
         "title": "D",
         "type": "number"
      },
      "1-rho": {
         "title": "1-Rho",
         "type": "number"
      },
      "phases_results": {
         "additionalProperties": {
            "$ref": "#/$defs/PhaseResult"
         },
         "title": "Phases Results",
         "type": "object"
      }
   },
   "$defs": {
      "PhaseResult": {
         "additionalProperties": true,
         "description": "The result for each phase.",
         "properties": {
            "SpacegroupNo": {
               "anyOf": [
                  {
                     "type": "integer"
                  },
                  {
                     "type": "null"
                  }
               ],
               "title": "Spacegroupno"
            },
            "HermannMauguin": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "title": "Hermannmauguin"
            },
            "XrayDensity": {
               "anyOf": [
                  {
                     "type": "number"
                  },
                  {
                     "type": "null"
                  }
               ],
               "title": "Xraydensity"
            },
            "Rphase": {
               "anyOf": [
                  {
                     "type": "number"
                  },
                  {
                     "type": "null"
                  }
               ],
               "title": "Rphase"
            },
            "UNIT": {
               "title": "Unit",
               "type": "string"
            },
            "GEWICHT": {
               "anyOf": [
                  {
                     "type": "number"
                  },
                  {
                     "maxItems": 2,
                     "minItems": 2,
                     "prefixItems": [
                        {
                           "type": "number"
                        },
                        {
                           "type": "number"
                        }
                     ],
                     "type": "array"
                  },
                  {
                     "type": "null"
                  }
               ],
               "title": "Gewicht"
            },
            "GEWICHT_NAME": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "title": "Gewicht Name"
            },
            "A": {
               "anyOf": [
                  {
                     "type": "number"
                  },
                  {
                     "maxItems": 2,
                     "minItems": 2,
                     "prefixItems": [
                        {
                           "type": "number"
                        },
                        {
                           "type": "number"
                        }
                     ],
                     "type": "array"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "A"
            },
            "B": {
               "anyOf": [
                  {
                     "type": "number"
                  },
                  {
                     "maxItems": 2,
                     "minItems": 2,
                     "prefixItems": [
                        {
                           "type": "number"
                        },
                        {
                           "type": "number"
                        }
                     ],
                     "type": "array"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "B"
            },
            "C": {
               "anyOf": [
                  {
                     "type": "number"
                  },
                  {
                     "maxItems": 2,
                     "minItems": 2,
                     "prefixItems": [
                        {
                           "type": "number"
                        },
                        {
                           "type": "number"
                        }
                     ],
                     "type": "array"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "C"
            },
            "ALPHA": {
               "anyOf": [
                  {
                     "type": "number"
                  },
                  {
                     "maxItems": 2,
                     "minItems": 2,
                     "prefixItems": [
                        {
                           "type": "number"
                        },
                        {
                           "type": "number"
                        }
                     ],
                     "type": "array"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "Alpha"
            },
            "BETA": {
               "anyOf": [
                  {
                     "type": "number"
                  },
                  {
                     "maxItems": 2,
                     "minItems": 2,
                     "prefixItems": [
                        {
                           "type": "number"
                        },
                        {
                           "type": "number"
                        }
                     ],
                     "type": "array"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "Beta"
            },
            "GAMMA": {
               "anyOf": [
                  {
                     "type": "number"
                  },
                  {
                     "maxItems": 2,
                     "minItems": 2,
                     "prefixItems": [
                        {
                           "type": "number"
                        },
                        {
                           "type": "number"
                        }
                     ],
                     "type": "array"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "Gamma"
            },
            "Atomic positions for phase": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "Atomic Positions For Phase"
            }
         },
         "required": [
            "SpacegroupNo",
            "HermannMauguin",
            "XrayDensity",
            "Rphase",
            "UNIT",
            "GEWICHT",
            "GEWICHT_NAME"
         ],
         "title": "PhaseResult",
         "type": "object"
      }
   },
   "additionalProperties": true,
   "required": [
      "raw_lst",
      "pattern_name",
      "num_steps",
      "Rp",
      "Rpb",
      "R",
      "Rwp",
      "Rexp",
      "d",
      "1-rho",
      "phases_results"
   ]
}

Fields:
field d: float [Required]#
field num_steps: int [Required]#
field pattern_name: str [Required]#
field phases_results: dict[str, PhaseResult] [Required]#
field r: float [Required] (alias 'R')#
field raw_lst: str [Required]#
field rexp: float [Required] (alias 'Rexp')#
field rho: float [Required] (alias '1-rho')#
field rp: float [Required] (alias 'Rp')#
field rpb: float [Required] (alias 'Rpb')#
field rwp: float [Required] (alias 'Rwp')#
exception ParseError[source]#

Bases: Exception

Error when parsing the result.

pydantic model PhaseResult[source]#

Bases: BaseModel

The result for each phase.

Show JSON schema
{
   "title": "PhaseResult",
   "description": "The result for each phase.",
   "type": "object",
   "properties": {
      "SpacegroupNo": {
         "anyOf": [
            {
               "type": "integer"
            },
            {
               "type": "null"
            }
         ],
         "title": "Spacegroupno"
      },
      "HermannMauguin": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "title": "Hermannmauguin"
      },
      "XrayDensity": {
         "anyOf": [
            {
               "type": "number"
            },
            {
               "type": "null"
            }
         ],
         "title": "Xraydensity"
      },
      "Rphase": {
         "anyOf": [
            {
               "type": "number"
            },
            {
               "type": "null"
            }
         ],
         "title": "Rphase"
      },
      "UNIT": {
         "title": "Unit",
         "type": "string"
      },
      "GEWICHT": {
         "anyOf": [
            {
               "type": "number"
            },
            {
               "maxItems": 2,
               "minItems": 2,
               "prefixItems": [
                  {
                     "type": "number"
                  },
                  {
                     "type": "number"
                  }
               ],
               "type": "array"
            },
            {
               "type": "null"
            }
         ],
         "title": "Gewicht"
      },
      "GEWICHT_NAME": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "title": "Gewicht Name"
      },
      "A": {
         "anyOf": [
            {
               "type": "number"
            },
            {
               "maxItems": 2,
               "minItems": 2,
               "prefixItems": [
                  {
                     "type": "number"
                  },
                  {
                     "type": "number"
                  }
               ],
               "type": "array"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "A"
      },
      "B": {
         "anyOf": [
            {
               "type": "number"
            },
            {
               "maxItems": 2,
               "minItems": 2,
               "prefixItems": [
                  {
                     "type": "number"
                  },
                  {
                     "type": "number"
                  }
               ],
               "type": "array"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "B"
      },
      "C": {
         "anyOf": [
            {
               "type": "number"
            },
            {
               "maxItems": 2,
               "minItems": 2,
               "prefixItems": [
                  {
                     "type": "number"
                  },
                  {
                     "type": "number"
                  }
               ],
               "type": "array"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "C"
      },
      "ALPHA": {
         "anyOf": [
            {
               "type": "number"
            },
            {
               "maxItems": 2,
               "minItems": 2,
               "prefixItems": [
                  {
                     "type": "number"
                  },
                  {
                     "type": "number"
                  }
               ],
               "type": "array"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Alpha"
      },
      "BETA": {
         "anyOf": [
            {
               "type": "number"
            },
            {
               "maxItems": 2,
               "minItems": 2,
               "prefixItems": [
                  {
                     "type": "number"
                  },
                  {
                     "type": "number"
                  }
               ],
               "type": "array"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Beta"
      },
      "GAMMA": {
         "anyOf": [
            {
               "type": "number"
            },
            {
               "maxItems": 2,
               "minItems": 2,
               "prefixItems": [
                  {
                     "type": "number"
                  },
                  {
                     "type": "number"
                  }
               ],
               "type": "array"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Gamma"
      },
      "Atomic positions for phase": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Atomic Positions For Phase"
      }
   },
   "additionalProperties": true,
   "required": [
      "SpacegroupNo",
      "HermannMauguin",
      "XrayDensity",
      "Rphase",
      "UNIT",
      "GEWICHT",
      "GEWICHT_NAME"
   ]
}

Fields:
Validators:
field a: Optional[Union[float, tuple[float, float]]] = None (alias 'A')#
Validated by:
field alpha: Optional[Union[float, tuple[float, float]]] = None (alias 'ALPHA')#
Validated by:
field atom_positions_string: Optional[str] = None (alias 'Atomic positions for phase')#
Validated by:
field b: Optional[Union[float, tuple[float, float]]] = None (alias 'B')#
Validated by:
field beta: Optional[Union[float, tuple[float, float]]] = None (alias 'BETA')#
Validated by:
field c: Optional[Union[float, tuple[float, float]]] = None (alias 'C')#
Validated by:
field gamma: Optional[Union[float, tuple[float, float]]] = None (alias 'GAMMA')#
Validated by:
field gewicht: Union[float, tuple[float, float], None] [Required] (alias 'GEWICHT')#
Validated by:
field gewicht_name: Optional[str] [Required] (alias 'GEWICHT_NAME')#
Validated by:
field hermann_mauguin: Optional[str] [Required] (alias 'HermannMauguin')#
Validated by:
field rphase: Optional[float] [Required] (alias 'Rphase')#
Validated by:
field spacegroup_no: Optional[int] [Required] (alias 'SpacegroupNo')#
Validated by:
field unit: str [Required] (alias 'UNIT')#
Validated by:
field xray_density: Optional[float] [Required] (alias 'XrayDensity')#
Validated by:
validator check_gewicht  »  all fields[source]#
get_structure()[source]#

Get the refined structure from the phase result.

Return type:

Structure

Returns:

the refined structure as pymatgen.Structure object

pydantic model RefinementResult[source]#

Bases: BaseModel

The result from the refinement, which is parsed from the .lst and .dia files.

Show JSON schema
{
   "title": "RefinementResult",
   "type": "object",
   "properties": {
      "lst_data": {
         "$ref": "#/$defs/LstResult"
      },
      "plot_data": {
         "$ref": "#/$defs/DiaResult"
      },
      "peak_data": {
         "default": null,
         "title": "Peak Data"
      }
   },
   "$defs": {
      "DiaResult": {
         "description": "Refinement result parsed from the .dia file. Mainly some x-y data for plotting.",
         "properties": {
            "x": {
               "items": {
                  "type": "number"
               },
               "title": "X",
               "type": "array"
            },
            "y_obs": {
               "items": {
                  "type": "number"
               },
               "title": "Y Obs",
               "type": "array"
            },
            "y_calc": {
               "items": {
                  "type": "number"
               },
               "title": "Y Calc",
               "type": "array"
            },
            "y_bkg": {
               "items": {
                  "type": "number"
               },
               "title": "Y Bkg",
               "type": "array"
            },
            "structs": {
               "additionalProperties": {
                  "items": {
                     "type": "number"
                  },
                  "type": "array"
               },
               "title": "Structs",
               "type": "object"
            }
         },
         "required": [
            "x",
            "y_obs",
            "y_calc",
            "y_bkg",
            "structs"
         ],
         "title": "DiaResult",
         "type": "object"
      },
      "LstResult": {
         "additionalProperties": true,
         "description": "Refinement result parsed from the .lst file.",
         "properties": {
            "raw_lst": {
               "title": "Raw Lst",
               "type": "string"
            },
            "pattern_name": {
               "title": "Pattern Name",
               "type": "string"
            },
            "num_steps": {
               "title": "Num Steps",
               "type": "integer"
            },
            "Rp": {
               "title": "Rp",
               "type": "number"
            },
            "Rpb": {
               "title": "Rpb",
               "type": "number"
            },
            "R": {
               "title": "R",
               "type": "number"
            },
            "Rwp": {
               "title": "Rwp",
               "type": "number"
            },
            "Rexp": {
               "title": "Rexp",
               "type": "number"
            },
            "d": {
               "title": "D",
               "type": "number"
            },
            "1-rho": {
               "title": "1-Rho",
               "type": "number"
            },
            "phases_results": {
               "additionalProperties": {
                  "$ref": "#/$defs/PhaseResult"
               },
               "title": "Phases Results",
               "type": "object"
            }
         },
         "required": [
            "raw_lst",
            "pattern_name",
            "num_steps",
            "Rp",
            "Rpb",
            "R",
            "Rwp",
            "Rexp",
            "d",
            "1-rho",
            "phases_results"
         ],
         "title": "LstResult",
         "type": "object"
      },
      "PhaseResult": {
         "additionalProperties": true,
         "description": "The result for each phase.",
         "properties": {
            "SpacegroupNo": {
               "anyOf": [
                  {
                     "type": "integer"
                  },
                  {
                     "type": "null"
                  }
               ],
               "title": "Spacegroupno"
            },
            "HermannMauguin": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "title": "Hermannmauguin"
            },
            "XrayDensity": {
               "anyOf": [
                  {
                     "type": "number"
                  },
                  {
                     "type": "null"
                  }
               ],
               "title": "Xraydensity"
            },
            "Rphase": {
               "anyOf": [
                  {
                     "type": "number"
                  },
                  {
                     "type": "null"
                  }
               ],
               "title": "Rphase"
            },
            "UNIT": {
               "title": "Unit",
               "type": "string"
            },
            "GEWICHT": {
               "anyOf": [
                  {
                     "type": "number"
                  },
                  {
                     "maxItems": 2,
                     "minItems": 2,
                     "prefixItems": [
                        {
                           "type": "number"
                        },
                        {
                           "type": "number"
                        }
                     ],
                     "type": "array"
                  },
                  {
                     "type": "null"
                  }
               ],
               "title": "Gewicht"
            },
            "GEWICHT_NAME": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "title": "Gewicht Name"
            },
            "A": {
               "anyOf": [
                  {
                     "type": "number"
                  },
                  {
                     "maxItems": 2,
                     "minItems": 2,
                     "prefixItems": [
                        {
                           "type": "number"
                        },
                        {
                           "type": "number"
                        }
                     ],
                     "type": "array"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "A"
            },
            "B": {
               "anyOf": [
                  {
                     "type": "number"
                  },
                  {
                     "maxItems": 2,
                     "minItems": 2,
                     "prefixItems": [
                        {
                           "type": "number"
                        },
                        {
                           "type": "number"
                        }
                     ],
                     "type": "array"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "B"
            },
            "C": {
               "anyOf": [
                  {
                     "type": "number"
                  },
                  {
                     "maxItems": 2,
                     "minItems": 2,
                     "prefixItems": [
                        {
                           "type": "number"
                        },
                        {
                           "type": "number"
                        }
                     ],
                     "type": "array"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "C"
            },
            "ALPHA": {
               "anyOf": [
                  {
                     "type": "number"
                  },
                  {
                     "maxItems": 2,
                     "minItems": 2,
                     "prefixItems": [
                        {
                           "type": "number"
                        },
                        {
                           "type": "number"
                        }
                     ],
                     "type": "array"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "Alpha"
            },
            "BETA": {
               "anyOf": [
                  {
                     "type": "number"
                  },
                  {
                     "maxItems": 2,
                     "minItems": 2,
                     "prefixItems": [
                        {
                           "type": "number"
                        },
                        {
                           "type": "number"
                        }
                     ],
                     "type": "array"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "Beta"
            },
            "GAMMA": {
               "anyOf": [
                  {
                     "type": "number"
                  },
                  {
                     "maxItems": 2,
                     "minItems": 2,
                     "prefixItems": [
                        {
                           "type": "number"
                        },
                        {
                           "type": "number"
                        }
                     ],
                     "type": "array"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "Gamma"
            },
            "Atomic positions for phase": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "Atomic Positions For Phase"
            }
         },
         "required": [
            "SpacegroupNo",
            "HermannMauguin",
            "XrayDensity",
            "Rphase",
            "UNIT",
            "GEWICHT",
            "GEWICHT_NAME"
         ],
         "title": "PhaseResult",
         "type": "object"
      }
   },
   "required": [
      "lst_data",
      "plot_data"
   ]
}

Fields:
Validators:
field lst_data: LstResult [Required]#
field peak_data: pd.DataFrame [Required]#
Validated by:
field plot_data: DiaResult [Required]#
export_structure(phase_name)[source]#

Export the refined structure from the phase result.

Parameters:

phase_name (str) – the name of the phase

Return type:

Structure

Returns:

the refined structure as pymatgen.Structure object

get_phase_weights(normalize=True)[source]#

Return the weights for each phase. Default is to normalize and return weight fractions.

Parameters:

normalize – Whether to normalize and return weight fractions. Defaults to True.

Return type:

dict[str, float]

Returns:

An ordered dictionary of phase names and their weights.

validator transform  »  peak_data[source]#

Create pandas dataframe from peak data dict.

Return type:

DataFrame

visualize(diff_offset=False)[source]#
get_result(control_file)[source]#

Get the result from the refinement.

Parameters:

control_file (Path) – the path to the control file (.sav)

Return type:

RefinementResult

parse_dia(dia_path, phase_names)[source]#

Get the results from the .dia file. This file mainly contains curves for the refinement.

// layout of the scanHeap: // [0] = 2theta // [1] = iObs // [2] = iCalc // [3] = iBkgr // [4…n] = strucs

Return type:

DiaResult

parse_lst(lst_path, phase_names)[source]#

Get results from the .lst file. This file mainly contains some numbers for the refinement.

Example of the .lst file:

Rietveld refinement to file(s) Mg3MnNi3O8.xy
BGMN version 4.2.23, 8301 measured points, 78 peaks, 20 parameters
Start: Mon Dec 18 11:43:20 2023; End: Mon Dec 18 11:43:21 2023
43 iteration steps

Rp=4.14%  Rpb=50.39%  R=13.55%  Rwp=8.98% Rexp=1.47%
Durbin-Watson d=0.06
1-rho=13.6%

Global parameters and GOALs
****************************
QMg3MnNi3O8166sym=0.0700+-0.0046
QNiO=0.9300+-0.0046
EPS2=-0.001657+-0.000033

Local parameters and GOALs for phase Mg3MnNi3O8166sym
******************************************************
SpacegroupNo=166
HermannMauguin=R-32/m
XrayDensity=4.943
Rphase=26.64%
UNIT=NM
A=0.5898+-0.0013
C=1.4449+-0.0062
k1=1.00000
B1=0.00492+-0.00076
GEWICHT=0.0288+-0.0019
GrainSize(1,1,1)=64.7+-10.0
Atomic positions for phase Mg3MnNi3O8166sym
---------------------------------------------
  9     0.5000  0.0000  0.0000     E=(MG(1.0000))
  3     0.0000  0.0000  0.0000     E=(MN(1.0000))
  9     0.5000  0.0000  0.5000     E=(NI(1.0000))
 18     0.0268 -0.0268  0.7429     E=(O(1.0000))
  6     0.0000  0.0000  0.2511     E=(O(1.0000))

Local parameters and GOALs for phase NiO
******************************************************
SpacegroupNo=225
HermannMauguin=F4/m-32/m
XrayDensity=6.760
Rphase=11.31%
UNIT=NM
A=0.418697+-0.000027
k1=0
B1=0.00798+-0.00022
GEWICHT=0.3827+-0.0049
GrainSize(1,1,1)=53.2+-1.5
Atomic positions for phase NiO
---------------------------------------------
  4     0.0000  0.0000  0.0000     E=(NI+2(1.0000))
  4     0.5000  0.5000  0.5000     E=(O-2(1.0000))
Parameters:

lst_path (Path)

Return type:

LstResult

Returns:

phase_results: a dictionary of the results for each phase

parse_par(par_file, phase_names)[source]#

Get the parameters from the .par file (hkl).

Only work for Cu K alpha!!!

Return type:

DataFrame