Exemplo n.º 1
0
 def test_set_atom_type(self):
     oxygen, hydrogen, component, _, _ = self.get_mocked_hierarchy()
     atom = Atom(
         parent = component,
         name = "O",
         atom_type = oxygen,
     )
     atom.atom_type = hydrogen
     self.assertEqual(atom.atom_type, hydrogen)
Exemplo n.º 2
0
 def test_set_atom_type(self):
     oxygen, hydrogen, component, _, _ = self.get_mocked_hierarchy()
     atom = Atom(
         parent=component,
         name="O",
         atom_type=oxygen,
     )
     atom.atom_type = hydrogen
     self.assertEqual(atom.atom_type, hydrogen)
Exemplo n.º 3
0
 def test_z_calculations(self):
     # Checks wether the atom can calculate stretched values:
     # 1. When everything is set up the way it should be:
     default_z = 9.0
     lattice_d = 5.4
     factor = 0.5
     class DummyComponent(object):
         def get_interlayer_stretch_factors(self):
             return lattice_d, factor
     parent = DummyComponent()
     atom = Atom(parent=parent)
     atom.stretch_values = True
     atom.default_z = default_z
     z = atom.z
     self.assertEqual(z, lattice_d + (default_z - lattice_d) * factor)
     # 2. When no component is set, but stretched is True: should not raise an error, but simple ignore the stretching
     atom.parent = None
     z = atom.z
Exemplo n.º 4
0
class TestAtom(unittest.TestCase):

    atom_type = None

    def setUp(self):
        self.atom = Atom()

    def tearDown(self):
        del self.atom

    def test_not_none(self):
        self.assertIsNotNone(self.atom)

    def test_data_object(self):
        self.assertIsNotNone(self.atom.data_object)

    test_name = create_object_attribute_test("atom", "name", "Test Name")
    test_pn = create_object_attribute_test("atom", "pn", 3)
    test_default_z = create_object_attribute_test("atom", "default_z", 5.3)
    test_stretch_values = create_object_attribute_test("atom",
                                                       "stretch_values", True)

    def test_parent(self):
        parent_atom = Atom(name="Parent")
        self.atom.parent = parent_atom
        self.assertEqual(self.atom.parent, parent_atom)

    def test_z_calculations(self):
        # Checks wether the atom can calculate stretched values:
        # 1. When everything is set up the way it should be:
        default_z = 9.0
        lattice_d = 5.4
        factor = 0.5

        class DummyComponent(object):
            def get_interlayer_stretch_factors(self):
                return lattice_d, factor

        parent = DummyComponent()
        atom = Atom(parent=parent)
        atom.stretch_values = True
        atom.default_z = default_z
        z = atom.z
        self.assertEqual(z, lattice_d + (default_z - lattice_d) * factor)
        # 2. When no component is set, but stretched is True: should not raise an error, but simple ignore the stretching
        atom.parent = None
        z = atom.z

    def test_structure_factors(self):
        import numpy as np
        rng = 2.0 * np.sin(np.arange(30)) / 0.154056
        res = self.atom.get_structure_factors(rng)
        self.assertIsNotNone(res)

    pass  # end of class
Exemplo n.º 5
0
 def test_z_calculations(self):
     # Checks wether the atom can calculate stretched values:
     # 1. When everything is set up the way it should be:
     default_z = 9.0
     lattice_d = 5.4
     factor = 0.5
     
     parent = Mock()
     parent.configure_mock(**{
         'get_interlayer_stretch_factors.return_value': (lattice_d, factor)
     })
     
     atom = Atom(parent=parent)
     atom.stretch_values = True
     atom.default_z = default_z
     z = atom.z
     self.assertEqual(z, lattice_d + (default_z - lattice_d) * factor)
     # 2. When no component is set, but stretched is True: should not raise an error, but simple ignore the stretching
     atom.parent = None
     z = atom.z
Exemplo n.º 6
0
    def test_z_calculations(self):
        # Checks wether the atom can calculate stretched values:
        # 1. When everything is set up the way it should be:
        default_z = 9.0
        lattice_d = 5.4
        factor = 0.5

        class DummyComponent(object):
            def get_interlayer_stretch_factors(self):
                return lattice_d, factor

        parent = DummyComponent()
        atom = Atom(parent=parent)
        atom.stretch_values = True
        atom.default_z = default_z
        z = atom.z
        self.assertEqual(z, lattice_d + (default_z - lattice_d) * factor)
        # 2. When no component is set, but stretched is True: should not raise an error, but simple ignore the stretching
        atom.parent = None
        z = atom.z
Exemplo n.º 7
0
    def test_z_calculations(self):
        # Checks wether the atom can calculate stretched values:
        # 1. When everything is set up the way it should be:
        default_z = 9.0
        lattice_d = 5.4
        factor = 0.5

        parent = Mock()
        parent.configure_mock(**{
            'get_interlayer_stretch_factors.return_value': (lattice_d, factor)
        })

        atom = Atom(parent=parent)
        atom.stretch_values = True
        atom.default_z = default_z
        z = atom.z
        self.assertEqual(z, lattice_d + (default_z - lattice_d) * factor)
        # 2. When no component is set, but stretched is True: should not raise an error, but simple ignore the stretching
        atom.parent = None
        z = atom.z
Exemplo n.º 8
0
class TestAtom(unittest.TestCase):

    atom_type = None

    def setUp(self):
        self.atom = Atom()

    def tearDown(self):
        del self.atom

    def test_not_none(self):
        self.assertIsNotNone(self.atom)

    def test_data_object(self):
        self.assertIsNotNone(self.atom.data_object)

    test_name = create_object_attribute_test("atom", "name", "Test Name")
    test_pn = create_object_attribute_test("atom", "pn", 3)
    test_default_z = create_object_attribute_test("atom", "default_z", 5.3)
    test_stretch_values = create_object_attribute_test("atom", "stretch_values", True)

    def test_parent(self):
        parent_atom = Atom(name="Parent")
        self.atom.parent = parent_atom
        self.assertEqual(self.atom.parent, parent_atom)

    def test_z_calculations(self):
        # Checks wether the atom can calculate stretched values:
        # 1. When everything is set up the way it should be:
        default_z = 9.0
        lattice_d = 5.4
        factor = 0.5
        class DummyComponent(object):
            def get_interlayer_stretch_factors(self):
                return lattice_d, factor
        parent = DummyComponent()
        atom = Atom(parent=parent)
        atom.stretch_values = True
        atom.default_z = default_z
        z = atom.z
        self.assertEqual(z, lattice_d + (default_z - lattice_d) * factor)
        # 2. When no component is set, but stretched is True: should not raise an error, but simple ignore the stretching
        atom.parent = None
        z = atom.z

    def test_structure_factors(self):
        import numpy as np
        rng = 2.0 * np.sin(np.arange(30)) / 0.154056
        res = self.atom.get_structure_factors(rng)
        self.assertIsNotNone(res)

    pass # end of class
Exemplo n.º 9
0
    def test_loads_atom_type_by_name(self):
        atom_json_dict = {
            "uuid": "878341b04e9e11e2b238150ae229a525",
            "name": "O",
            "default_z": 0.66,
            "pn": 6.0,
            "atom_type_name": "O1-"
        }

        oxygen, _, component, _, _ = self.get_mocked_hierarchy()

        atom = Atom.from_json(parent=component, **atom_json_dict)
        atom.resolve_json_references()
        self.assertEqual(atom.atom_type, oxygen)
Exemplo n.º 10
0
 def test_loads_atom_type_by_name(self):
     atom_json_dict = {
         "uuid": "878341b04e9e11e2b238150ae229a525", 
         "name": "O", 
         "default_z": 0.66, 
         "pn": 6.0, 
         "atom_type_name": "O1-"
     }
     
     oxygen, _, component, _, _ = self.get_mocked_hierarchy()
     
     atom = Atom.from_json(parent = component, **atom_json_dict)
     atom.resolve_json_references()
     self.assertEqual(atom.atom_type, oxygen)
Exemplo n.º 11
0
 def on_accept(dialog):
     del self.treemodel_data[:] # clears the list
     Atom.get_from_csv(dialog.filename, self.treemodel_data.append, self.model)
Exemplo n.º 12
0
 def on_accept(open_dialog):
     filename = self.extract_filename(open_dialog, self.file_filters)
     self.treemodel_data.clear()
     Atom.get_from_csv(filename, self.treemodel_data.append, self.model)
Exemplo n.º 13
0
 def on_accept(save_dialog):
     Atom.save_as_csv(save_dialog.filename, self.get_all_objects())
Exemplo n.º 14
0
class TestAtom(unittest.TestCase):

    atom_type = None

    def setUp(self):
        self.atom = Atom()

    def tearDown(self):
        del self.atom

    def get_mocked_hierarchy(self):       
        oxygen = Mock()
        oxygen.name = "O1-"
        hydrogen = Mock()
        hydrogen.name = "H+"
                
        project = Mock()
        project.atom_types = [oxygen, hydrogen]
        phase = Mock()
        phase.attach_mock(project, 'project')
        component = Mock()
        component.attach_mock(phase, 'phase')
        
        return oxygen, hydrogen, component, phase, project

    def test_not_none(self):
        self.assertIsNotNone(self.atom)

    def test_data_object(self):
        self.assertIsNotNone(self.atom.data_object)

    test_name = create_object_attribute_test("atom", "name", "Test Name")
    test_pn = create_object_attribute_test("atom", "pn", 3)
    test_default_z = create_object_attribute_test("atom", "default_z", 5.3)
    test_stretch_values = create_object_attribute_test("atom", "stretch_values", True)

    def test_parent(self):
        parent_atom = Atom(name="Parent")
        self.atom.parent = parent_atom
        self.assertEqual(self.atom.parent, parent_atom)

    def test_set_atom_type(self):
        oxygen, hydrogen, component, _, _ = self.get_mocked_hierarchy()
        atom = Atom(
            parent = component,
            name = "O",
            atom_type = oxygen,
        )
        atom.atom_type = hydrogen
        self.assertEqual(atom.atom_type, hydrogen)

    def test_z_calculations(self):
        # Checks wether the atom can calculate stretched values:
        # 1. When everything is set up the way it should be:
        default_z = 9.0
        lattice_d = 5.4
        factor = 0.5
        
        parent = Mock()
        parent.configure_mock(**{
            'get_interlayer_stretch_factors.return_value': (lattice_d, factor)
        })
        
        atom = Atom(parent=parent)
        atom.stretch_values = True
        atom.default_z = default_z
        z = atom.z
        self.assertEqual(z, lattice_d + (default_z - lattice_d) * factor)
        # 2. When no component is set, but stretched is True: should not raise an error, but simple ignore the stretching
        atom.parent = None
        z = atom.z

    def test_structure_factors(self):
        import numpy as np
        rng = 2.0 * np.sin(np.arange(30)) / 0.154056
        res = self.atom.get_structure_factors(rng)
        self.assertIsNotNone(res)
        
    def test_loads_atom_type_by_name(self):
        atom_json_dict = {
            "uuid": "878341b04e9e11e2b238150ae229a525", 
            "name": "O", 
            "default_z": 0.66, 
            "pn": 6.0, 
            "atom_type_name": "O1-"
        }
        
        oxygen, _, component, _, _ = self.get_mocked_hierarchy()
        
        atom = Atom.from_json(parent = component, **atom_json_dict)
        atom.resolve_json_references()
        self.assertEqual(atom.atom_type, oxygen)
        

    pass # end of class
Exemplo n.º 15
0
 def on_accept(save_dialog):
     Atom.save_as_csv(save_dialog.filename, self.get_all_objects())
Exemplo n.º 16
0
 def create_new_object_proxy(self):
     return Atom(name="New Atom", parent=self.model)
Exemplo n.º 17
0
 def on_accept(dialog):
     del self.treemodel_data[:]  # clears the list
     Atom.get_from_csv(dialog.filename, self.treemodel_data.append,
                       self.model)
Exemplo n.º 18
0
 def on_accept(save_dialog):
     filename = self.extract_filename(save_dialog, self.file_filters)
     Atom.save_as_csv(filename, self.get_all_objects())
Exemplo n.º 19
0
 def setUp(self):
     self.atom = Atom()
Exemplo n.º 20
0
 def test_parent(self):
     parent_atom = Atom(name="Parent")
     self.atom.parent = parent_atom
     self.assertEqual(self.atom.parent, parent_atom)
Exemplo n.º 21
0
 def setUp(self):
     self.atom = Atom()
Exemplo n.º 22
0
class TestAtom(unittest.TestCase):

    atom_type = None

    def setUp(self):
        self.atom = Atom()

    def tearDown(self):
        del self.atom

    def get_mocked_hierarchy(self):
        oxygen = Mock()
        oxygen.name = "O1-"
        hydrogen = Mock()
        hydrogen.name = "H+"

        project = Mock()
        project.atom_types = [oxygen, hydrogen]
        phase = Mock()
        phase.attach_mock(project, 'project')
        component = Mock()
        component.attach_mock(phase, 'phase')

        return oxygen, hydrogen, component, phase, project

    def test_not_none(self):
        self.assertIsNotNone(self.atom)

    def test_data_object(self):
        self.assertIsNotNone(self.atom.data_object)

    test_name = create_object_attribute_test("atom", "name", "Test Name")
    test_pn = create_object_attribute_test("atom", "pn", 3)
    test_default_z = create_object_attribute_test("atom", "default_z", 5.3)
    test_stretch_values = create_object_attribute_test("atom",
                                                       "stretch_values", True)

    def test_parent(self):
        parent_atom = Atom(name="Parent")
        self.atom.parent = parent_atom
        self.assertEqual(self.atom.parent, parent_atom)

    def test_set_atom_type(self):
        oxygen, hydrogen, component, _, _ = self.get_mocked_hierarchy()
        atom = Atom(
            parent=component,
            name="O",
            atom_type=oxygen,
        )
        atom.atom_type = hydrogen
        self.assertEqual(atom.atom_type, hydrogen)

    def test_z_calculations(self):
        # Checks wether the atom can calculate stretched values:
        # 1. When everything is set up the way it should be:
        default_z = 9.0
        lattice_d = 5.4
        factor = 0.5

        parent = Mock()
        parent.configure_mock(**{
            'get_interlayer_stretch_factors.return_value': (lattice_d, factor)
        })

        atom = Atom(parent=parent)
        atom.stretch_values = True
        atom.default_z = default_z
        z = atom.z
        self.assertEqual(z, lattice_d + (default_z - lattice_d) * factor)
        # 2. When no component is set, but stretched is True: should not raise an error, but simple ignore the stretching
        atom.parent = None
        z = atom.z

    def test_structure_factors(self):
        import numpy as np
        rng = 2.0 * np.sin(np.arange(30)) / 0.154056
        res = self.atom.get_structure_factors(rng)
        self.assertIsNotNone(res)

    def test_loads_atom_type_by_name(self):
        atom_json_dict = {
            "uuid": "878341b04e9e11e2b238150ae229a525",
            "name": "O",
            "default_z": 0.66,
            "pn": 6.0,
            "atom_type_name": "O1-"
        }

        oxygen, _, component, _, _ = self.get_mocked_hierarchy()

        atom = Atom.from_json(parent=component, **atom_json_dict)
        atom.resolve_json_references()
        self.assertEqual(atom.atom_type, oxygen)

    pass  # end of class
Exemplo n.º 23
0
def create_project_from_sybilla_xml(filename, **kwargs):
    """
        Creates a new project structure from a Sybilla XML file.
        Some information (e.g. the actual XRD pattern) is not present and will
        still need to be imported manually.
    """

    tree = ET.parse(filename)
    root = tree.getroot()
    basename = os.path.basename(filename)

    # Create the project:
    if "name" in kwargs: kwargs.pop("name")
    if "layout_mode" in kwargs: kwargs.pop("layout_mode")
    project = Project(name=basename, layout_mode="FULL", **kwargs)

    # Add a specimen:
    specimen = Specimen(name=basename, parent=project)
    project.specimens.append(specimen)

    # Add a mixture:
    mixture = Mixture(name=basename, auto_run=False, parent=project)
    mixture.add_specimen_slot(specimen, 1.0, 0.0)
    project.mixtures.append(mixture)

    with project.data_changed.ignore():
        with mixture.data_changed.ignore():

            for child in root:
                if child.tag == "basic_params":
                    # Goniometer parameters:
                    step_size = safe_float(child.attrib['step_size'])
                    wavelength = safe_float(child.attrib['lambda']) / 10.0
                    steps = int(1 +
                                (specimen.goniometer.max_2theta -
                                 specimen.goniometer.min_2theta) / step_size)

                    specimen.goniometer.min_2theta = safe_float(
                        child.attrib['min2theta'])
                    specimen.goniometer.max_2theta = safe_float(
                        child.attrib['max2theta'])
                    specimen.goniometer.steps = steps
                    specimen.goniometer.wavelength = wavelength
                elif child.tag == "diffractometer":
                    # Some more goniometer parameters, and specimen parameters:
                    specimen.goniometer.radius = safe_float(
                        child.attrib['gonio_radius'])
                    specimen.goniometer.divergence = safe_float(
                        child.attrib['diverg_slit'])
                    specimen.goniometer.soller1 = safe_float(
                        child.attrib['Soller1'])
                    specimen.goniometer.soller2 = safe_float(
                        child.attrib['Soller2'])
                    specimen.sample_length = safe_float(
                        child.attrib['sample_length'])
                elif child.tag == "content":
                    # Content tag contains 'Mixture' data
                    for xmlPhaseContent in child:
                        name = xmlPhaseContent.attrib['name']
                        fraction = safe_float(
                            xmlPhaseContent.attrib['content']) / 100.
                        mixture.add_phase_slot(name, fraction)
                elif child.tag == "mixture":
                    # Mixture tag corresponds with the phases in the project level,
                    # not an actual Mixture object:
                    for xmlPhase in child:
                        name = xmlPhase.attrib['name']
                        sigma = xmlPhase.attrib['sigma_star']
                        csds = safe_float(
                            xmlPhase.find('distribution').attrib['Tmean'])
                        G = 1
                        R = 0
                        W = [
                            1.0,
                        ]
                        if xmlPhase.attrib['type'] != 'mono':
                            prob = xmlPhase.find('probability')
                            G = int(prob.attrib['no_of_comp'])
                            R = int(prob.attrib['R'])

                        # create phase and add to project:
                        phase = Phase(name=name,
                                      sigma_star=sigma,
                                      G=G,
                                      R=R,
                                      parent=project)
                        phase.CSDS_distribution.average = csds
                        project.phases.append(phase)

                        # set probability:
                        if R == 0 and G != 1:
                            xmlW = prob.find('W')
                            W = np.array([
                                float(
                                    int(
                                        safe_float(xmlW.attrib[
                                            string.ascii_lowercase[i]]) *
                                        1000.)) / 1000. for i in range(G)
                            ])
                            for i in range(G - 1):
                                setattr(phase.probabilities, "F%d" % (i + 1),
                                        W[i] / np.sum(W[i:]))
                        if R == 1 and G == 2:
                            pass  # TODO
                        # ... TODO other probs

                        # parse components:
                        for i, layer in enumerate(
                                xmlPhase.findall("./layer_and_edge/layer")):

                            component = phase.components[i]
                            component.name = layer.attrib['name']

                            component.d001 = safe_float(
                                layer.attrib['d_spacing']) / 10.0
                            component.default_c = safe_float(
                                layer.attrib['d_spacing']) / 10.0
                            component.delta_c = safe_float(
                                layer.attrib['d_spacing_delta']) / 10.0

                            component.ucp_b.value = 0.9

                            component.ucp_a.factor = 0.57735
                            component.ucp_a.prop = (component, 'cell_b')
                            component.ucp_a.enabled = True

                            atom_type_map = {
                                # "NH4": "FIXME"
                                "K": "K1+",
                                "O": "O1-",
                                "Si": "Si2+",
                                "OH": "OH1-",
                                "Fe": "Fe1.5+",
                                "Al": "Al1.5+",
                                "Mg": "Mg1+",
                                "H2O": "H2O",
                                "Gly": "Glycol",
                                "Ca": "Ca2+",
                                "Na": "Na1+",
                            }

                            # add atoms:
                            fe_atom = None
                            encountered_oxygen = False
                            for atom in layer.findall("atom"):
                                atom_type_name = atom_type_map.get(
                                    atom.attrib['type'], None)
                                if atom_type_name:
                                    if atom_type_name == "O1-":
                                        # From this point we're dealing with layer atoms
                                        encountered_oxygen = True
                                    atom = Atom(
                                        name=atom.attrib['type'],
                                        default_z=safe_float(
                                            atom.attrib['position']) / 10.0,
                                        pn=safe_float(atom.attrib['content']),
                                        atom_type_name=atom_type_name,
                                        parent=component)
                                    if encountered_oxygen:
                                        component.layer_atoms.append(atom)
                                    else:
                                        component.interlayer_atoms.append(atom)
                                    atom.resolve_json_references()
                                    # Assume this is the octahedral iron...
                                    if encountered_oxygen and atom_type_name == "Fe1.5+":
                                        fe_atom = atom

                            # Set the atom relation
                            if fe_atom is not None:
                                component.ucp_b.constant = 0.9
                                component.ucp_b.factor = 0.0043
                                component.ucp_b.prop = (fe_atom, 'pn')
                                component.ucp_b.enabled = True

                pass  # end of if
            pass  # end of for

            # Map phases onto mixture names:
            for phase in project.phases:
                for slot, phase_name in enumerate(mixture.phases):
                    if phase.name == phase_name:
                        mixture.set_phase(0, slot, phase)

    return project
Exemplo n.º 24
0
def create_project_from_sybilla_xml(filename, **kwargs):
    """
        Creates a new project structure from a Sybilla XML file.
        Some information (e.g. the actual XRD pattern) is not present and will
        still need to be imported manually.
    """

    tree = ET.parse(filename)
    root = tree.getroot()
    basename = os.path.basename(filename)

    # Create the project:
    if "name" in kwargs: kwargs.pop("name")
    if "layout_mode" in kwargs: kwargs.pop("layout_mode")
    project = Project(name=basename, layout_mode="FULL", **kwargs)

    # Add a specimen:
    specimen = Specimen(name=basename, parent=project)
    project.specimens.append(specimen)

    # Add a mixture:
    mixture = Mixture(name=basename, auto_run=False, parent=project)
    mixture.add_specimen_slot(specimen, 1.0, 0.0)
    project.mixtures.append(mixture)

    with project.data_changed.ignore():
        with mixture.data_changed.ignore():

            for child in root:
                if child.tag == "basic_params":
                    # Goniometer parameters:
                    step_size = safe_float(child.attrib['step_size'])
                    wavelength = safe_float(child.attrib['lambda']) / 10.0
                    steps = int(1 + (specimen.goniometer.max_2theta - specimen.goniometer.min_2theta) / step_size)

                    specimen.goniometer.min_2theta = safe_float(child.attrib['min2theta'])
                    specimen.goniometer.max_2theta = safe_float(child.attrib['max2theta'])
                    specimen.goniometer.steps = steps
                    specimen.goniometer.wavelength = wavelength
                elif child.tag == "diffractometer":
                    # Some more goniometer parameters, and specimen parameters:
                    specimen.goniometer.radius = safe_float(child.attrib['gonio_radius'])
                    specimen.goniometer.divergence = safe_float(child.attrib['diverg_slit'])
                    specimen.goniometer.soller1 = safe_float(child.attrib['Soller1'])
                    specimen.goniometer.soller2 = safe_float(child.attrib['Soller2'])
                    specimen.sample_length = safe_float(child.attrib['sample_length'])
                elif child.tag == "content":
                    # Content tag contains 'Mixture' data
                    for xmlPhaseContent in child:
                        name = xmlPhaseContent.attrib['name']
                        fraction = safe_float(xmlPhaseContent.attrib['content']) / 100.
                        mixture.add_phase_slot(name, fraction)
                elif child.tag == "mixture":
                    # Mixture tag corresponds with the phases in the project level,
                    # not an actual Mixture object:
                    for xmlPhase in child:
                        name = xmlPhase.attrib['name']
                        sigma = xmlPhase.attrib['sigma_star']
                        csds = safe_float(xmlPhase.find('distribution').attrib['Tmean'])
                        G = 1
                        R = 0
                        W = [1.0, ]
                        if xmlPhase.attrib['type'] != 'mono':
                            prob = xmlPhase.find('probability')
                            G = int(prob.attrib['no_of_comp'])
                            R = int(prob.attrib['R'])

                        # create phase and add to project:
                        phase = Phase(name=name, sigma_star=sigma, G=G, R=R, parent=project)
                        phase.CSDS_distribution.average = csds
                        project.phases.append(phase)

                        # set probability:
                        if R == 0 and G != 1:
                            xmlW = prob.find('W')
                            W = np.array([ float(int(safe_float(xmlW.attrib[string.ascii_lowercase[i]]) * 1000.)) / 1000. for i in range(G) ])
                            for i in range(G - 1):
                                setattr(phase.probabilities, "F%d" % (i + 1), W[i] / np.sum(W[i:]))
                        if R == 1 and G == 2:
                            pass  # TODO
                        # ... TODO other probs

                        # parse components:
                        for i, layer in enumerate(xmlPhase.findall("./layer_and_edge/layer")):

                            component = phase.components[i]
                            component.name = layer.attrib['name']

                            component.d001 = safe_float(layer.attrib['d_spacing']) / 10.0
                            component.default_c = safe_float(layer.attrib['d_spacing']) / 10.0
                            component.delta_c = safe_float(layer.attrib['d_spacing_delta']) / 10.0

                            component.ucp_b.value = 0.9

                            component.ucp_a.factor = 0.57735
                            component.ucp_a.prop = (component, 'cell_b')
                            component.ucp_a.enabled = True


                            atom_type_map = {
                                # "NH4": "FIXME"
                                "K": "K1+",
                                "O": "O1-",
                                "Si": "Si2+",
                                "OH": "OH1-",
                                "Fe": "Fe1.5+",
                                "Al": "Al1.5+",
                                "Mg": "Mg1+",
                                "H2O": "H2O",
                                "Gly": "Glycol",
                                "Ca": "Ca2+",
                                "Na": "Na1+",
                            }

                            # add atoms:
                            fe_atom = None
                            encountered_oxygen = False
                            for atom in layer.findall("atom"):
                                atom_type_name = atom_type_map.get(atom.attrib['type'], None)
                                if atom_type_name:
                                    if atom_type_name == "O1-":
                                        # From this point we're dealing with layer atoms
                                        encountered_oxygen = True
                                    atom = Atom(
                                        name=atom.attrib['type'],
                                        default_z=safe_float(atom.attrib['position']) / 10.0,
                                        pn=safe_float(atom.attrib['content']),
                                        atom_type_name=atom_type_name,
                                        parent=component
                                    )
                                    if encountered_oxygen:
                                        component.layer_atoms.append(atom)
                                    else:
                                        component.interlayer_atoms.append(atom)
                                    atom.resolve_json_references()
                                    # Assume this is the octahedral iron...
                                    if encountered_oxygen and atom_type_name == "Fe1.5+":
                                        fe_atom = atom

                            # Set the atom relation
                            if fe_atom is not None:
                                component.ucp_b.constant = 0.9
                                component.ucp_b.factor = 0.0043
                                component.ucp_b.prop = (fe_atom, 'pn')
                                component.ucp_b.enabled = True

                pass # end of if
            pass # end of for


            # Map phases onto mixture names:
            for phase in project.phases:
                for slot, phase_name in enumerate(mixture.phases):
                    if phase.name == phase_name:
                        mixture.set_phase(0, slot, phase)

    return project