Пример #1
0
    def import_cif_file(self):
        file = self.ui.cif_file.text()

        if not os.path.isfile(file):
            return

        try:
            cf = ReadCif(file)

            search_params = {
                '_cell_length_a': InterplanarSpacing.PARAMETER_A,
                '_cell_length_b': InterplanarSpacing.PARAMETER_B,
                '_cell_length_c': InterplanarSpacing.PARAMETER_C,
                '_cell_angle_alpha': InterplanarSpacing.PARAMETER_ALPHA,
                '_cell_angle_beta': InterplanarSpacing.PARAMETER_BETA,
                '_cell_angle_gamma': InterplanarSpacing.PARAMETER_GAMMA,
            }

            ui_mapping = self.get_parameter_mapping()
            import re
            # find the lattice parameters in the cif file
            for key, entry in cf.items():
                for search_key, search_mapping in search_params.items():
                    if entry.has_key(search_key):
                        try:
                            number = float(entry[search_key])
                        except:
                            number = re.findall(r"[-+]?\d*\.\d+|\d+",
                                                entry[search_key])
                            if len(number) == 0:
                                continue
                            number = number[0]
                        ui_mapping[search_mapping].setText(str(number))

            self.system.set_parameter(self.get_lattice_parameters())

            system_class = self.system.detect_system()
            # Now set the input text field for the crystal system
            crystal_family = None
            for key, crystal_class in self.CLASS_MAPPING.items():
                if crystal_class == system_class:
                    crystal_family = key

            self.set_crystal_family(crystal_family)

            self.update_view()

        except BaseException as e:
            print(e)
Пример #2
0
def read_structure(path_to_file):

    cwd = os.getcwd()
    try:
        os.chdir(os.path.dirname(path_to_file))
        file_name = os.path.split(path_to_file)[-1]
        cif_data = ReadCif(file_name)
        os.chdir(cwd)
    except:
        os.chdir(cwd)
        raise ValueError("The reading or parsing of the " + file_name +
                         " is failed!")
    try:
        name, data = list(cif_data.items())[0]
        structure_data = StructureData(name, data)
        structure = Structure().build_structure(structure_data)
        structure.reamove_connectivity()
        return structure
    except:
        print("Reading structure is failed!")
Пример #3
0
def read_structures(path_to_file):

    cwd = os.getcwd()
    try:
        os.chdir(os.path.dirname(path_to_file))
        file_name = os.path.split(path_to_file)[-1]
        cif_data = ReadCif(file_name)
        os.chdir(cwd)
    except:
        os.chdir(cwd)
        raise ValueError("The reading or parsing of the " + file_name +
                         " is failed!")
    for i, (name, data) in enumerate(cif_data.items()):
        try:
            structure_data = StructureData(name, data)
            structure = Structure().build_structure(structure_data)
            structure.reamove_connectivity()
            yield structure
        except:
            os.chdir(cwd)
            print("Reading " + str(i) + " structure is failed!")
Пример #4
0
from CifFile import ReadCif

cf = ReadCif('4_SnO2_0.0288nm.cif')
for key,value in cf.items():
    #print( '{0}{1}'.format(key,value) )
    print( type(value))