def test_get_lattices(self): sm = StructureMatcher(ltol=0.2, stol=0.3, angle_tol=5, primitive_cell=True, scale=True, attempt_supercell=False) l1 = Lattice.from_lengths_and_angles([1, 2.1, 1.9], [90, 89, 91]) l2 = Lattice.from_lengths_and_angles([1.1, 2, 2], [89, 91, 90]) s1 = Structure(l1, [], []) s2 = Structure(l2, [], []) lattices = list(sm._get_lattices(s=s1, target_lattice=s2.lattice)) self.assertEqual(len(lattices), 16) l3 = Lattice.from_lengths_and_angles([1.1, 2, 20], [89, 91, 90]) s3 = Structure(l3, [], []) lattices = list(sm._get_lattices(s=s1, target_lattice=s3.lattice)) self.assertEqual(len(lattices), 0)
def material_properties(result): """ """ atoms = [] for i, species in enumerate(result.species): for j in range(result.composition[i]): # Since AFLOW return value like ['Al', 'Si/n'], /n is needed to be gone! if len(species) > 2: atoms.append(species[:-2]) else: atoms.append(species) lat = Lattice.from_lengths_and_angles(result.geometry[:3], result.geometry[3:]) mat_property = { 'catalog': result.catalog, 'formula': result.compound, 'lattice': lat.matrix, 'coordinates': result.positions_fractional, 'atom_array': atoms, 'form_energy_cell': result.enthalpy_formation_cell, 'n_atoms': result.natoms, 'volume': result.volume_cell, 'space_group': result.spacegroup_relax } return mat_property
def test_get_lattices(self): sm = StructureMatcher(ltol=0.2, stol=0.3, angle_tol=5, primitive_cell=True, scale=True, attempt_supercell=False) l1 = Lattice.from_lengths_and_angles([1, 2.1, 1.9] , [90, 89, 91]) l2 = Lattice.from_lengths_and_angles([1.1, 2, 2] , [89, 91, 90]) s1 = Structure(l1, [], []) s2 = Structure(l2, [], []) lattices = list(sm._get_lattices(s = s1, target_s = s2)) self.assertEqual(len(lattices), 16) l3 = Lattice.from_lengths_and_angles([1.1, 2, 20] , [89, 91, 90]) s3 = Structure(l3, [], []) lattices = list(sm._get_lattices(s = s1, target_s = s3)) self.assertEqual(len(lattices), 0)
def lattice(self): # lattice matrix: basis vectors are rows si = self["=.in"].structure_information # todo: convert non-angstrom units assert si.lengthunit.type == 2 lattice = Lattice.from_lengths_and_angles(abc=si.lattice_constants, ang=si.axis_angles) return lattice
def material_properties(result, dos): """ """ atoms = [] for i, species in enumerate(result.species): for j in range(result.composition[i]): atoms.append(species) lat = Lattice.from_lengths_and_angles(result.geometry[:3], result.geometry[3:]) mat_property = { 'formula': result.compound, 'lattice': lat.matrix, 'coordinates': result.positions_fractional, 'atom_array': atoms, 'form_energy_cell': result.enthalpy_formation_cell, 'n_atoms': result.natoms, 'volume': result.volume_cell, 'space_group': result.spacegroup_relax, 'dos_fermi': dos } return mat_property
data = np.genfromtxt("./pcu_2.log", skip_footer=29, skip_header=17) a_mean = [] b_mean = [] c_mean = [] alpha_mean = [] beta_mean = [] gamma_mean = [] vol_mean = [] mechanical_eig_max = [] mechanical_eig_min = [] temp = [] h = [] for frame in data: lattice = Lattice.from_lengths_and_angles( [frame[14], frame[15], frame[16]], [frame[17], frame[18], frame[19]]) hmatrix = lattice.matrix h.append(hmatrix) a_mean.append(np.mean(data[:, 14])) b_mean.append(np.mean(data[:, 15])) c_mean.append(np.mean(data[:, 16])) alpha_mean.append(np.mean(data[:, 17])) beta_mean.append(np.mean(data[:, 18])) gamma_mean.append(np.mean(data[:, 19])) vol_mean.append(np.mean(data[:, 13])) temp.append(np.mean(data[:, 11])) h = np.array(h) h0 = np.mean(h, axis=0) h0_std = np.std(h, axis=0)
def FromString(self, contents): ScaleConstant = {'Ang': 1, 'Bohr': 0.5291772083} params_pattern = re.compile('^([A-Za-z]*) (.*)\n', re.M) block_pattern = re.compile( '^%block (?P<n>[A-Za-z_]*)(.*)%endblock *(?P=n)', re.DOTALL | re.M) params = params_pattern.findall(contents) blocks = block_pattern.findall(contents) # Making Dictionary from raw list, deliting all \n entries block_dict = { blocks[i][0]: blocks[i][1].strip().replace('\n', ' ') for i in range(0, len(blocks)) } param_dict = { params[i][0]: params[i][1].strip() for i in range(0, len(params)) } # print "Full FDF Dictionary:\n", block_dict if 'LatticeVectors' in block_dict.keys(): lattice_list = np.array( block_dict['LatticeVectors'].strip().split()).astype(float) lattice = Lattice(lattice_list) elif 'LatticeParameters' in block_dict.keys(): lattice_list = np.array( block_dict['LatticeParameters'].strip().split()).astype(float) lattice = Lattice.from_lengths_and_angles(lattice_list[:3], lattice_list[3:]) print lattice_list[:3], '\n', lattice_list[3:] # print "Lattice Matrix:\n" , lattice.matrix # print "Siesta input parameters:\n", param_dict # Getting Coordinates matrix if 'AtomicCoordinatesAndAtomicSpecies' in block_dict.keys(): Coords = block_dict['AtomicCoordinatesAndAtomicSpecies'] npCoord = np.array(Coords.split()).astype(float) if npCoord.size % 4 == 0: npCoord = npCoord.reshape(npCoord.size / 4, 4) # Sorting table by element number npCoord = npCoord[np.lexsort(npCoord.T)] # Getting labels of Chemical elements ChemSpec = np.array(block_dict['ChemicalSpeciesLabel'].split()) if ChemSpec.size % 3 == 0: ChemSpec = ChemSpec.reshape(ChemSpec.size / 3, 3) Elems = [] for x in npCoord: Elems.append(ChemSpec[x[3] - 1][2]) # Checking Coordinates format and converting bohr to ang if necessery LatticeConstant = param_dict['LatticeConstant'].strip().split() inCartesian = False CoordFormat = param_dict['AtomicCoordinatesFormat'] if CoordFormat: if CoordFormat in ('Ang', 'NotScaledCartesianAng'): inCartesian = True elif CoordFormat in ('Bohr', 'NotScaledCartesianBohr'): inCartesian = True npCoord[:, :-1] *= ScaleConstant['Bohr'] elif CoordFormat == 'ScaledCartesian': inCartesian = True npCoord[:, :-1] *= ScaleConstant[LatticeConstant[1]] * float( LatticeConstant[0]) struct = Structure(lattice, Elems, npCoord[:, :-1], inCartesian) print '---------------\n', struct.to_dict, '\n---------------\n' return contents