def read_geometry(self): """ Read geometry from the contained file """ # First we read in the geometry sc = self.read_supercell() # Try and go to the first model record in_model, l = self._step_record('MODEL') idx = [] tags = [] xyz = [] Z = [] if in_model: l = self.readline() def is_atom(line): return l.startswith('ATOM') or l.startswith('HETATM') def is_end_model(line): return l.startswith('ENDMDL') or l == '' while not is_end_model(l): if is_atom(l): idx.append(int(l[6:11])) tags.append(l[12:16].strip()) xyz.append( [float(l[30:38]), float(l[38:46]), float(l[46:54])]) Z.append(l[76:78].strip()) l = self.readline() # First sort all atoms according to the idx array idx = np.array(idx) idx = np.argsort(idx) xyz = np.array(xyz)[idx, :] tags = [tags[i] for i in idx] Z = [Z[i] for i in idx] # Create the atom list atoms = Atoms(Atom(Z[0], tag=tags[0]), na=len(Z)) for i, a in enumerate(map(Atom, Z, tags)): try: s = atoms.index(a) except: s = len(atoms.atom) atoms._atom.append(a) atoms._specie[i] = s return Geometry(xyz, atoms, sc=sc)
def test_index1(): atom = Atoms(['C', 'Au']) with pytest.raises(KeyError): atom.index(Atom('B'))
def test_index1(): atom = Atoms(['C', 'Au']) atom.index(Atom('B'))