|
4 | 4 | """Generate Gaussian input file.""" |
5 | 5 |
|
6 | 6 | import itertools |
| 7 | +import re |
7 | 8 | import uuid |
8 | 9 | import warnings |
9 | 10 | from typing import List, Optional, Tuple, Union |
@@ -272,3 +273,68 @@ def make_gaussian_input( |
272 | 273 | ) |
273 | 274 | buff.append("\n") |
274 | 275 | return "\n".join(buff) |
| 276 | + |
| 277 | + |
| 278 | +def read_gaussian_input(inp: str): |
| 279 | + """Read Gaussian input. |
| 280 | +
|
| 281 | + Parameters |
| 282 | + ---------- |
| 283 | + inp : str |
| 284 | + Gaussian input str |
| 285 | +
|
| 286 | + Returns |
| 287 | + ------- |
| 288 | + dict |
| 289 | + system data |
| 290 | + """ |
| 291 | + flag = 0 |
| 292 | + coords = [] |
| 293 | + elements = [] |
| 294 | + cells = [] |
| 295 | + for line in inp.split("\n"): |
| 296 | + if not line.strip(): |
| 297 | + # empty line |
| 298 | + flag += 1 |
| 299 | + elif flag == 0: |
| 300 | + # keywords |
| 301 | + if line.startswith("#"): |
| 302 | + # setting |
| 303 | + keywords = line.split() |
| 304 | + elif line.startswith("%"): |
| 305 | + pass |
| 306 | + elif flag == 1: |
| 307 | + # title |
| 308 | + pass |
| 309 | + elif flag == 2: |
| 310 | + # multi and coords |
| 311 | + s = line.split() |
| 312 | + if len(s) == 2: |
| 313 | + pass |
| 314 | + elif len(s) == 4: |
| 315 | + if s[0] == "TV": |
| 316 | + cells.append(list(map(float, s[1:4]))) |
| 317 | + else: |
| 318 | + # element |
| 319 | + elements.append(re.sub("\\(.*?\\)|\\{.*?}|\\[.*?]", "", s[0])) |
| 320 | + coords.append(list(map(float, s[1:4]))) |
| 321 | + elif flag == 3: |
| 322 | + # end |
| 323 | + break |
| 324 | + atom_names, atom_types, atom_numbs = np.unique( |
| 325 | + elements, return_inverse=True, return_counts=True |
| 326 | + ) |
| 327 | + if len(cells): |
| 328 | + nopbc = False |
| 329 | + else: |
| 330 | + nopbc = True |
| 331 | + cells = np.array([np.eye(3)]) * 100 |
| 332 | + return { |
| 333 | + "atom_names": list(atom_names), |
| 334 | + "atom_numbs": list(atom_numbs), |
| 335 | + "atom_types": atom_types, |
| 336 | + "cells": np.array(cells).reshape(1, 3, 3), |
| 337 | + "nopbc": nopbc, |
| 338 | + "coords": np.array(coords).reshape(1, -1, 3), |
| 339 | + "orig": np.zeros(3), |
| 340 | + } |
0 commit comments