Esempio n. 1
0
    def test_approximate_rotational_invariance(self):
        descriptor = DISH(configs=self.configs)

        # build crystal structures - two different random rotations
        fcc_al = crystal('Al', [(0, 0, 0)],
                         spacegroup=225,
                         cellpar=[4.05, 4.05, 4.05, 90, 90, 90])
        fcc_all_supercell_rot1 = create_supercell(fcc_al, target_nb_atoms=128)
        fcc_all_supercell_rot2 = create_supercell(fcc_al, target_nb_atoms=128)

        # rotate 1st structure
        alphas = (random.random() * 360.0, random.random() * 360.0,
                  random.random() * 360.0)
        fcc_all_supercell_rot1.rotate(alphas[0],
                                      'x',
                                      rotate_cell=True,
                                      center='COU')
        fcc_all_supercell_rot1.rotate(alphas[1],
                                      'y',
                                      rotate_cell=True,
                                      center='COU')
        fcc_all_supercell_rot1.rotate(alphas[2],
                                      'z',
                                      rotate_cell=True,
                                      center='COU')

        # rotate 2nd structure
        alphas = (random.random() * 360.0, random.random() * 360.0,
                  random.random() * 360.0)
        fcc_all_supercell_rot2.rotate(alphas[0],
                                      'x',
                                      rotate_cell=True,
                                      center='COU')
        fcc_all_supercell_rot2.rotate(alphas[1],
                                      'y',
                                      rotate_cell=True,
                                      center='COU')
        fcc_all_supercell_rot2.rotate(alphas[2],
                                      'z',
                                      rotate_cell=True,
                                      center='COU')

        # calculate the descriptor
        descriptor.calculate(fcc_all_supercell_rot1)
        descriptor.calculate(fcc_all_supercell_rot2)
        spectrum_rot1 = fcc_all_supercell_rot1.info['descriptor'][
            'diffraction_3d_sh_spectrum']
        spectrum_rot2 = fcc_all_supercell_rot2.info['descriptor'][
            'diffraction_3d_sh_spectrum']

        # test if the two diffraction fingerprints are different by less than 20% (20% is arbitrary)
        self.assertLessEqual(np.abs(np.amax(spectrum_rot1 - spectrum_rot2)),
                             0.20)
Esempio n. 2
0
    def test_approximate_size_invariance(self):
        descriptor = DISH(configs=self.configs)

        # build crystal structures - two supercell sizes
        fcc_al = crystal('Al', [(0, 0, 0)],
                         spacegroup=225,
                         cellpar=[4.05, 4.05, 4.05, 90, 90, 90])
        structure_128 = create_supercell(fcc_al, target_nb_atoms=128)
        structure_256 = create_supercell(fcc_al, target_nb_atoms=256)

        # calculate the descriptor
        descriptor.calculate(structure_128)
        descriptor.calculate(structure_256)
        intensity_128 = structure_128.info['descriptor'][
            'diffraction_3d_sh_spectrum']
        intensity_256 = structure_256.info['descriptor'][
            'diffraction_3d_sh_spectrum']

        # test if the two diffraction fingerprints are different by less than 20% (20% is arbitrary)
        self.assertLessEqual(np.abs(np.amax(intensity_256 - intensity_128)),
                             0.20)
Esempio n. 3
0
    def test_approximate_translational_invariance(self):
        # build crystal structures - one translated w.r.t. the other by an arbitrary vector
        structure = crystal('Al', [(0, 0, 0)],
                            spacegroup=225,
                            cellpar=[4.05, 4.05, 4.05, 90, 90, 90])
        trans_vector = [1.0, -2.0, 5.0]
        structure_translated = structure.copy()
        structure_translated.translate(trans_vector)
        structure = create_supercell(structure, target_nb_atoms=128)
        structure_translated = create_supercell(structure_translated,
                                                target_nb_atoms=128)

        # calculate the descriptor
        descriptor = DISH(configs=self.configs)
        descriptor.calculate(structure)
        descriptor.calculate(structure_translated)
        intensity = structure.info['descriptor']['diffraction_3d_sh_spectrum']
        intensity_translated = structure_translated.info['descriptor'][
            'diffraction_3d_sh_spectrum']

        # test if the two diffraction fingerprints are different by less than 20% (20% is arbitrary)
        np.testing.assert_allclose(intensity, intensity_translated, 0.2)
Esempio n. 4
0
    def test_normalization(self):
        descriptor = DISH(configs=self.configs)

        # build crystal structure
        bcc_fe = crystal('Fe', [(0, 0, 0)],
                         spacegroup=229,
                         cellpar=[4.05, 4.05, 4.05, 90, 90, 90])
        structure = create_supercell(bcc_fe, target_nb_atoms=256)

        # calculate the descriptor
        descriptor.calculate(structure)
        intensity = structure.info['descriptor']['diffraction_3d_sh_spectrum']

        # check if intensity_rgb is normalized
        self.assertAlmostEqual(np.amax(intensity), 1.0)
        self.assertAlmostEqual(np.amin(intensity), 0.0)
Esempio n. 5
0
    def test_size_invariance(self):
        # replicating a unit cell must not change the atomic features
        structure = crystal('C', [(0, 0, 0)], spacegroup=227, cellpar=[3.57, 3.57, 3.57, 90, 90, 90])
        structure_supercell = create_supercell(structure, target_nb_atoms=128)

        # define descriptor
        selected_feature_list = ['atomic_ionization_potential', 'atomic_electron_affinity', 'atomic_rs_max']
        kwargs = {'feature_order_by': 'atomic_mulliken_electronegativity', 'energy_unit': 'eV',
                  'length_unit': 'angstrom'}
        descriptor = AtomicFeatures(configs=self.configs, **kwargs)

        # calculate descriptor
        descriptor.calculate(structure, selected_feature_list=selected_feature_list)
        df_atomic_features = structure.info['descriptor']['atomic_features_table']
        descriptor.calculate(structure_supercell, selected_feature_list=selected_feature_list)
        df_atomic_features_supercell = structure_supercell.info['descriptor']['atomic_features_table']

        self.assertIsInstance(df_atomic_features, pd.DataFrame)
        self.assertIsInstance(df_atomic_features_supercell, pd.DataFrame)
Esempio n. 6
0
                                          random_rotation_before=True,
                                          cell_type='standard_no_symmetries',
                                          optimal_supercell=False)),
                                    (random_displace_atoms,
                                     dict(noise_distribution='gaussian',
                                          displacement=0.10,
                                          create_replicas_by='nb_atoms',
                                          min_nb_atoms=32,
                                          target_nb_atoms=256,
                                          random_rotation=False,
                                          random_rotation_before=True,
                                          cell_type='standard_no_symmetries',
                                          optimal_supercell=False))]

    # =============================================================================
    # Descriptor calculation
    # =============================================================================

    # create the fcc aluminium structure
    nacl = crystal(['Na', 'Cl'], [(0, 0, 0), (0.5, 0.5, 0.5)],
                   spacegroup=225,
                   cellpar=[5.64, 5.64, 5.64, 90, 90, 90])

    structure = create_supercell(nacl, target_nb_atoms=256)

    # calculate the two-dimensional diffraction fingerprint
    structure_result = descriptor.calculate(structure)
    rdf = structure_result.info['descriptor']['rdf']

    logger.info("Calculation completed.")
Esempio n. 7
0
    # setup folder and files
    main_folder = '/home/ziletti/Documents/nomadml_docs'
    desc_folder = os.path.abspath(os.path.normpath(os.path.join(main_folder, 'desc_folder')))
    # checkpoint_folder = os.path.abspath(os.path.normpath(os.path.join(main_folder, 'saved_models')))
    figure_folder = os.path.abspath(os.path.normpath(os.path.join(main_folder, 'attentive_resp_maps')))
    checkpoint_folder = os.path.abspath(os.path.normpath('../assets/data_examples/'))

    # build crystal structures
    fcc_al = crystal('Al', [(0, 0, 0)], spacegroup=225, cellpar=[4.05, 4.05, 4.05, 90, 90, 90])
    bcc_fe = crystal('Fe', [(0, 0, 0)], spacegroup=229, cellpar=[2.87, 2.87, 2.87, 90, 90, 90])
    diamond_c = crystal('C', [(0, 0, 0)], spacegroup=227, cellpar=[3.57, 3.57, 3.57, 90, 90, 90])
    hcp_mg = crystal('Mg', [(1. / 3., 2. / 3., 3. / 4.)], spacegroup=194, cellpar=[3.21, 3.21, 5.21, 90, 90, 120])

    # create supercells - pristine
    fcc_al_supercell = create_supercell(fcc_al, target_nb_atoms=128, cell_type='standard_no_symmetries')
    bcc_fe_supercell = create_supercell(bcc_fe, target_nb_atoms=128, cell_type='standard_no_symmetries')
    diamond_c_supercell = create_supercell(diamond_c, target_nb_atoms=128, cell_type='standard_no_symmetries')
    hcp_mg_supercell = create_supercell(hcp_mg, target_nb_atoms=128, cell_type='standard_no_symmetries')

    ase_atoms_list = [fcc_al_supercell, bcc_fe_supercell, diamond_c_supercell, hcp_mg_supercell]

    # calculate the two-dimensional diffraction fingerprint for all four structures
    descriptor = Diffraction2D(configs=configs)
    diffraction_fingerprints_rgb = [descriptor.calculate(ase_atoms).info['descriptor']['diffraction_2d_intensity'] for ase_atoms in ase_atoms_list]

    neural_network_name = 'ziletti_et_2018_rgb'
    model_weights_file = os.path.abspath(os.path.normpath(os.path.join(checkpoint_folder, neural_network_name + '.h5')))
    model_arch_file = os.path.abspath(os.path.normpath(os.path.join(checkpoint_folder, neural_network_name + '.json')))

    # convert list of diffraction fingerprint images to to numpy array