Example #1
0
 def _read_lattice(self, line):
     """Read the lattice vectors"""
     line = self.file_descriptor.readline()
     line = self.file_descriptor.readline()
     x = float(line.split()[0])
     y = float(line.split()[1])
     z = float(line.split()[2])
     avector = [x, y, z]
     line = self.file_descriptor.readline()
     x = float(line.split()[0])
     y = float(line.split()[1])
     z = float(line.split()[2])
     bvector = [x, y, z]
     line = self.file_descriptor.readline()
     x = float(line.split()[0])
     y = float(line.split()[1])
     z = float(line.split()[2])
     cvector = [x, y, z]
     cell = UnitCell(avector, bvector, cvector)
     self.unit_cells.append(cell)
     self.volume = cell.volume
     self.ncells = len(self.unit_cells)
     # Convert fractional coordinates to cartesians
     if len(self._cartesian_coordinates) == 0:
         if len(self._fractional_coordinates) == 0:
             print("Error no coordinates fraction or cartesian found")
             exit()
         for atom_frac in self._fractional_coordinates:
             atom_cart = cell.convert_abc_to_xyz(atom_frac)
             self.cartesian_coordinates.append(atom_cart)
         # end for
     # end if
     self.unit_cells[-1].set_fractional_coordinates(self._fractional_coordinates)
     self.unit_cells[-1].set_element_names(self._atom_types)
Example #2
0
 def _read_crystal_axes(self, line):
     linea = self.file_descriptor.readline().split()
     avector = [float(f) * self._alat / angs2bohr for f in linea[3:6]]
     linea = self.file_descriptor.readline().split()
     bvector = [float(f) * self._alat / angs2bohr for f in linea[3:6]]
     linea = self.file_descriptor.readline().split()
     cvector = [float(f) * self._alat / angs2bohr for f in linea[3:6]]
     self.unit_cells.append(UnitCell(avector, bvector, cvector))
     self.ncells = len(self.unit_cells)
     self.volume = self.unit_cells[-1].volume
     return
Example #3
0
 def _read_lattice_vectors(self, line):
     linea = self.file_descriptor.readline().split()
     avector = [float(f) * self._alat / angs2bohr for f in linea[0:3]]
     linea = self.file_descriptor.readline().split()
     bvector = [float(f) * self._alat / angs2bohr for f in linea[0:3]]
     linea = self.file_descriptor.readline().split()
     cvector = [float(f) * self._alat / angs2bohr for f in linea[0:3]]
     self.unit_cells.append(UnitCell(avector, bvector, cvector))
     self.ncells = len(self.unit_cells)
     self.volume = self.unit_cells[-1].volume
     self._read_masses()
     return
Example #4
0
 def _read_lattice_vectors(self, line):
     self.volume = float(line.split()[4])
     line = self.file_descriptor.readline()
     line = self.file_descriptor.readline()
     avector = [
         float(line.split()[0]),
         float(line.split()[1]),
         float(line.split()[2])
     ]
     line = self.file_descriptor.readline()
     bvector = [
         float(line.split()[0]),
         float(line.split()[1]),
         float(line.split()[2])
     ]
     line = self.file_descriptor.readline()
     cvector = [
         float(line.split()[0]),
         float(line.split()[1]),
         float(line.split()[2])
     ]
     cell = UnitCell(avector, bvector, cvector)
     if self.ncells > 0:
         cell.set_fractional_coordinates(
             self.unit_cells[-1].fractional_coordinates)
         cell.set_element_names(self.species_list)
     self.unit_cells.append(cell)
     self.ncells = len(self.unit_cells)
     return
Example #5
0
 def _read_lattice_vectors(self, line):
     linea = line.split()
     avector = [float(linea[1]), float(linea[2]), float(linea[3])]
     linea = self.file_descriptor.readline().split()
     bvector = [float(linea[0]), float(linea[1]), float(linea[2])]
     linea = self.file_descriptor.readline().split()
     cvector = [float(linea[0]), float(linea[1]), float(linea[2])]
     avector = [f * self._acell[0] for f in avector]
     bvector = [f * self._acell[1] for f in bvector]
     cvector = [f * self._acell[2] for f in cvector]
     self.unit_cells.append(UnitCell(avector, bvector, cvector))
     self.ncells = len(self.unit_cells)
     self.volume = self.unit_cells[-1].volume
     return
 def _read_lattice_vectors(self, line):
     line = self.file_descriptor.readline()
     line = self.file_descriptor.readline()
     avector = [float(line.split()[0]), float(line.split()[1]), float(line.split()[2])]
     line = self.file_descriptor.readline()
     bvector = [float(line.split()[0]), float(line.split()[1]), float(line.split()[2])]
     line = self.file_descriptor.readline()
     cvector = [float(line.split()[0]), float(line.split()[1]), float(line.split()[2])]
     self.unit_cells.append(UnitCell(avector, bvector, cvector))
     self.ncells = len(self.unit_cells)
     self.volume = self.unit_cells[-1].volume
     # The fractional coordinates are specified before the lattice vectors
     self.unit_cells[-1].set_fractional_coordinates(self._fractional_coordinates)
     self.unit_cells[-1].set_element_names(self.species_list)
     return
 def _read_lattice_vectors(self, line):
     scalar = float(line.split()[1])
     line = self.file_descriptor.readline()
     avector = [
         scalar * float(line.split()[0]), scalar * float(line.split()[1]),
         scalar * float(line.split()[2])
     ]
     line = self.file_descriptor.readline()
     bvector = [
         scalar * float(line.split()[0]), scalar * float(line.split()[1]),
         scalar * float(line.split()[2])
     ]
     line = self.file_descriptor.readline()
     cvector = [
         scalar * float(line.split()[0]), scalar * float(line.split()[1]),
         scalar * float(line.split()[2])
     ]
     cell = UnitCell(avector, bvector, cvector)
     self.unit_cells.append(cell)
     self.ncells = len(self.unit_cells)
     self.volume = cell.volume
     return
Example #8
0
 def _read_cellcontents(self, line):
     line = self._read_till_phrase(re.compile(' *Real Lattice'))
     line = self.file_descriptor.readline()
     avector = [
         float(line.split()[0]),
         float(line.split()[1]),
         float(line.split()[2])
     ]
     line = self.file_descriptor.readline()
     bvector = [
         float(line.split()[0]),
         float(line.split()[1]),
         float(line.split()[2])
     ]
     line = self.file_descriptor.readline()
     cvector = [
         float(line.split()[0]),
         float(line.split()[1]),
         float(line.split()[2])
     ]
     self.unit_cells.append(UnitCell(avector, bvector, cvector))
     self.ncells = len(self.unit_cells)
     line = self._read_till_phrase(re.compile(' *Current cell volume'))
     self.volume = float(line.split()[4])
     if self.nions == 0:
         line = self._read_till_phrase(
             re.compile(' *Total number of ions in cell'))
         if len(self.unit_cells) == 1:
             self.nions = int(line.split()[7])
             line = self.file_descriptor.readline()
             self.nspecies = int(line.split()[7])
             line = self.file_descriptor.readline()
             line = self.file_descriptor.readline()
         line = self.file_descriptor.readline()
         line = self.file_descriptor.readline()
         line = self.file_descriptor.readline()
         line = self.file_descriptor.readline()
     # end if self.nions
     else:
         # Not all Unit Cell output is the same in Castep 17
         line = self._read_till_phrase(
             re.compile(' *xxxxxxxxxxxxxxxxxxxxxxxxxxxx'))
         line = self.file_descriptor.readline()
         line = self.file_descriptor.readline()
         line = self.file_descriptor.readline()
     # end of else
     fractional_coordinates = []
     # ions_per_type is a dictionary here and is local
     ions_per_type = {}
     self.atom_type_list = []
     self.species = []
     species_list = []
     for i in range(self.nions):
         line = self.file_descriptor.readline()
         atom_type = line.split()[1].capitalize()
         species_list.append(atom_type)
         if atom_type not in ions_per_type:
             self.species.append(atom_type)
             ions_per_type[atom_type] = 0
         self.atom_type_list.append(self.species.index(atom_type))
         ions_per_type[atom_type] += 1
         atom_frac = [float(f) for f in line.split()[3:6]]
         fractional_coordinates.append(atom_frac)
     # At some point we should store the fractional coordinates
     for species in self.species:
         n = ions_per_type[species]
         # self.ions_per_type is a list
         self.ions_per_type.append(n)
     self.unit_cells[-1].set_fractional_coordinates(fractional_coordinates)
     self.unit_cells[-1].set_element_names(species_list)
     return