def run(args):
    if args and args.filename != "":
        project = Project.load_object(args.filename)

        default_atoms = []

        AtomType.get_from_csv(
            settings.DATA_REG.get_file_path("ATOM_SCAT_FACTORS"),
            default_atoms.append
        )

        for atom in project.atom_types.iter_objects():

            default_atom = None
            for def_atom in default_atoms:
                if atom.name == def_atom.name:
                    default_atom = def_atom
            assert default_atom is not None

            atom.charge = default_atom.charge
            atom.debye = default_atom.debye

        project.save_object(args.filename + ".def")

        del project

        print "Finished!"
Exemple #2
0
 def on_accept(save_dialog):
     fltr = save_dialog.get_filter()
     filename = self.extract_filename(save_dialog, self.file_filters)
     if fltr.get_name() == self.file_filters[0][0]:
         AtomType.save_atom_types(filename, self.get_selected_objects())
     elif fltr.get_name() == self.file_filters[1][0]:
         AtomType.save_as_csv(filename, self.get_selected_objects())
Exemple #3
0
 def load_atom_types(self, filename):
     """
     Loads all :class:`~pyxrd.atoms.models.AtomType` objects from the JSON
     file specified by *filename*.
     """
     for atom_type in AtomType.load_atom_types(filename, parent=self):
         self.atom_types.append(atom_type)
class TestAtomType(unittest.TestCase):

    atom_type = None

    def setUp(self):
        self.atom_type = AtomType()

    def tearDown(self):
        del self.atom_type

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

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

    test_name = create_object_attribute_test("atom_type", "name", "Test Name")
    test_charge = create_object_attribute_test("atom_type", "charge", -5)
    test_debye = create_object_attribute_test("atom_type", "debye", 1.0)
    test_weight = create_object_attribute_test("atom_type", "weight", 60.123)
    test_atom_nr = create_object_attribute_test("atom_type", "atom_nr", 20)
    test_par_c = create_object_attribute_test("atom_type", "par_c", 10.2)
    test_par_a1 = create_object_attribute_test("atom_type", "par_a1", 10.2)
    test_par_a2 = create_object_attribute_test("atom_type", "par_a2", 10.2)
    test_par_a3 = create_object_attribute_test("atom_type", "par_a3", 10.2)
    test_par_a4 = create_object_attribute_test("atom_type", "par_a4", 10.2)
    test_par_a5 = create_object_attribute_test("atom_type", "par_a5", 10.2)
    test_par_b1 = create_object_attribute_test("atom_type", "par_b1", 10.2)
    test_par_b2 = create_object_attribute_test("atom_type", "par_b2", 10.2)
    test_par_b3 = create_object_attribute_test("atom_type", "par_b3", 10.2)
    test_par_b4 = create_object_attribute_test("atom_type", "par_b4", 10.2)
    test_par_b5 = create_object_attribute_test("atom_type", "par_b5", 10.2)

    def test_parent(self):
        parent_atom_type = AtomType(name="Parent")
        self.atom_type.parent = parent_atom_type
        self.assertEqual(self.atom_type.parent, parent_atom_type)
        
    def test_get_atomic_scattering_factors(self):
        import numpy as np
        stl_range = np.array([ 0.1152, 0.5756, 1.1469 ])
        self.atom_type.par_a1 = 10.2
        self.atom_type.par_a2 = 10.2
        self.atom_type.par_a3 = 10.2
        self.atom_type.par_a4 = 10.2
        self.atom_type.par_a5 = 10.2
        self.atom_type.par_b1 = 10.2
        self.atom_type.par_b2 = 10.2
        self.atom_type.par_b3 = 10.2
        self.atom_type.par_b4 = 10.2
        self.atom_type.par_b5 = 10.2
        self.atom_type.par_c = 20.2
        self.assertListEqual(
            self.atom_type.get_atomic_scattering_factors(stl_range).tolist(),
            [ 71.1827439324707, 70.77093939463964, 69.51772020477823 ]
        )

    pass # end of class
Exemple #5
0
class TestAtomType(unittest.TestCase):

    atom_type = None

    def setUp(self):
        self.atom_type = AtomType()

    def tearDown(self):
        del self.atom_type

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

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

    test_name = create_object_attribute_test("atom_type", "name", "Test Name")
    test_charge = create_object_attribute_test("atom_type", "charge", -5)
    test_debye = create_object_attribute_test("atom_type", "debye", 1.0)
    test_weight = create_object_attribute_test("atom_type", "weight", 60.123)
    test_atom_nr = create_object_attribute_test("atom_type", "atom_nr", 20)
    test_par_c = create_object_attribute_test("atom_type", "par_c", 10.2)
    test_par_a1 = create_object_attribute_test("atom_type", "par_a1", 10.2)
    test_par_a2 = create_object_attribute_test("atom_type", "par_a2", 10.2)
    test_par_a3 = create_object_attribute_test("atom_type", "par_a3", 10.2)
    test_par_a4 = create_object_attribute_test("atom_type", "par_a4", 10.2)
    test_par_a5 = create_object_attribute_test("atom_type", "par_a5", 10.2)
    test_par_b1 = create_object_attribute_test("atom_type", "par_b1", 10.2)
    test_par_b2 = create_object_attribute_test("atom_type", "par_b2", 10.2)
    test_par_b3 = create_object_attribute_test("atom_type", "par_b3", 10.2)
    test_par_b4 = create_object_attribute_test("atom_type", "par_b4", 10.2)
    test_par_b5 = create_object_attribute_test("atom_type", "par_b5", 10.2)

    def test_parent(self):
        parent_atom_type = AtomType(name="Parent")
        self.atom_type.parent = parent_atom_type
        self.assertEqual(self.atom_type.parent, parent_atom_type)

    def test_get_atomic_scattering_factors(self):
        import numpy as np
        stl_range = np.array([0.1152, 0.5756, 1.1469])
        self.atom_type.par_a1 = 10.2
        self.atom_type.par_a2 = 10.2
        self.atom_type.par_a3 = 10.2
        self.atom_type.par_a4 = 10.2
        self.atom_type.par_a5 = 10.2
        self.atom_type.par_b1 = 10.2
        self.atom_type.par_b2 = 10.2
        self.atom_type.par_b3 = 10.2
        self.atom_type.par_b4 = 10.2
        self.atom_type.par_b5 = 10.2
        self.atom_type.par_c = 20.2
        self.assertListEqual(
            self.atom_type.get_atomic_scattering_factors(stl_range).tolist(),
            [71.1827439324707, 70.77093939463964, 69.51772020477823])

    pass  # end of class
Exemple #6
0
 def test_parent(self):
     parent_atom_type = AtomType(name="Parent")
     self.atom_type.parent = parent_atom_type
     self.assertEqual(self.atom_type.parent, parent_atom_type)
Exemple #7
0
 def setUp(self):
     self.atom_type = AtomType()
 def setUp(self):
     self.atom_type = AtomType()
Exemple #9
0
 def load_default_data(self):
     for atom_type in AtomType.get_from_csv(
             settings.DATA_REG.get_file_path("ATOM_SCAT_FACTORS")):
         self.atom_types.append(atom_type)
Exemple #10
0
 def create_new_object_proxy(self):
     return AtomType(name="New Atom Type", parent=self.model)
Exemple #11
0
 def load_default_data(self):
     for atom_type in AtomType.get_from_csv(settings.DATA_REG.get_file_path("ATOM_SCAT_FACTORS")):
         self.atom_types.append(atom_type)