def __init__(self, filename):
self.filename = filename<EOL>def skip_to(f, linestart):<EOL><INDENT>while True:<EOL><INDENT>line = f.readline()<EOL>if line.startswith(linestart):<EOL><INDENT>return line<EOL><DEDENT>if len(line) == <NUM_LIT:0>:<EOL><INDENT>return<EOL><DEDENT><DEDENT><DEDENT>with open(filename) as f:<EOL><INDENT>line = skip_to(f, '<STR_LIT>')<EOL>if line is None:<EOL><INDENT>raise FileFormatError('<STR_LIT>')<EOL><DEDENT>f.readline()<EOL>f.readline()<EOL>vectors = []<EOL>for i in range(<NUM_LIT:3>):<EOL><INDENT>line = f.readline()<EOL>vectors.append([float(word) for word in line.split()[<NUM_LIT:1>:]])<EOL><DEDENT>vectors = np.array(vectors)<EOL>self.unit_cell = UnitCell(vectors.transpose())<EOL>line = skip_to(f, '<STR_LIT>')<EOL>if line is None:<EOL><INDENT>raise FileFormatError('<STR_LIT>')<EOL><DEDENT>f.readline()<EOL>f.readline()<EOL>f.readline()<EOL>numbers = []<EOL>symbols = []<EOL>coordinates = []<EOL>while True:<EOL><INDENT>line = f.readline()<EOL>if line.startswith('<STR_LIT>'):<EOL><INDENT>break<EOL><DEDENT>words = line.split()<EOL>numbers.append(int(words[<NUM_LIT:1>]))<EOL>symbols.append(words[<NUM_LIT:2>])<EOL>coordinates.append([float(words[<NUM_LIT:3>]), float(words[<NUM_LIT:4>]), float(words[<NUM_LIT:5>])])<EOL><DEDENT>self.mol = Molecule(np.array(numbers), np.array(coordinates), symbols=symbols, unit_cell=self.unit_cell)<EOL>line = skip_to(f, '<STR_LIT>')<EOL>if line is None:<EOL><INDENT>raise FileFormatError('<STR_LIT>')<EOL><DEDENT>f.readline()<EOL>f.readline()<EOL>f.readline()<EOL>f.readline()<EOL>f.readline()<EOL>f.readline()<EOL>self.basisset = {}<EOL>last_basis = None<EOL>last_contraction = None<EOL>while True:<EOL><INDENT>line = f.readline()<EOL>if line.startswith('<STR_LIT>'):<EOL><INDENT>break<EOL><DEDENT>if line.startswith('<STR_LIT:U+0020>'):<EOL><INDENT>assert last_basis is not None<EOL>subshell = line[<NUM_LIT>:<NUM_LIT>].strip()<EOL>if len(subshell) == <NUM_LIT:0>:<EOL><INDENT>subshell = last_contraction[<NUM_LIT:0>]<EOL>exponent = float(line[<NUM_LIT>:<NUM_LIT:50>])<EOL>if subshell == '<STR_LIT:S>':<EOL><INDENT>values = exponent, float(line[<NUM_LIT:50>:<NUM_LIT>])<EOL><DEDENT>elif subshell == '<STR_LIT>':<EOL><INDENT>values = exponent, float(line[<NUM_LIT:50>:<NUM_LIT>]), float(line[<NUM_LIT>:<NUM_LIT>])<EOL><DEDENT>else:<EOL><INDENT>values = exponent, float(line[<NUM_LIT>:<NUM_LIT>])<EOL><DEDENT>last_contraction[<NUM_LIT:1>].append(values)<EOL><DEDENT>else:<EOL><INDENT>last_contraction = (subshell, [])<EOL>last_basis.append(last_contraction)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>symbol = line.split()[<NUM_LIT:1>]<EOL>if symbol not in self.basisset:<EOL><INDENT>last_basis = []<EOL>self.basisset[symbol] = last_basis<EOL><DEDENT><DEDENT><DEDENT>self.num_basis = <NUM_LIT:0><EOL>subshell_counts = {'<STR_LIT:S>': <NUM_LIT:1>, '<STR_LIT:P>': <NUM_LIT:3>, '<STR_LIT>': <NUM_LIT:4>, '<STR_LIT:D>': <NUM_LIT:5>, '<STR_LIT:F>': <NUM_LIT:7>, '<STR_LIT>': <NUM_LIT:9>}<EOL>for symbol, basis in self.basisset.items():<EOL><INDENT>symbol_count = symbols.count(symbol)<EOL>for subshell, contraction in basis:<EOL><INDENT>self.num_basis += symbol_count*subshell_counts[subshell]<EOL><DEDENT><DEDENT>line = skip_to(f, '<STR_LIT>')<EOL>if line is None:<EOL><INDENT>raise FileFormatError('<STR_LIT>')<EOL><DEDENT>f.readline()<EOL>f.readline()<EOL>f.readline()<EOL>self.density_matrix = np.zeros((self.num_basis, self.num_basis), float)<EOL>j0 = <NUM_LIT:0><EOL>while j0 < self.num_basis:<EOL><INDENT>f.readline()<EOL>f.readline()<EOL>f.readline()<EOL>for i in range(self.num_basis):<EOL><INDENT>line = f.readline()<EOL>words = line.split()[<NUM_LIT:1>:]<EOL>for j1, word in enumerate(words):<EOL><INDENT>self.density_matrix[i,j0 + j1] = float(word)<EOL><DEDENT><DEDENT>j0 += <NUM_LIT:10><EOL><DEDENT><DEDENT>
Arguments:
 | ``filename`` -- The file to load.