Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ The `System` or `LabeledSystem` can be constructed from the following file forma
| lammps | lmp | False | False | System | 'lammps/lmp' |
| lammps | dump | True | False | System | 'lammps/dump' |
| deepmd | raw | True | True | LabeledSystem | 'deepmd/raw' |
| gaussian| log | False | True | LabeledSystem | 'gaussian/log'|



Expand Down
60 changes: 60 additions & 0 deletions dpdata/gaussian/log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import numpy as np


hartree2ev = 27.211386018
bohr2ang = 0.52917721067

length_convert = bohr2ang
energy_convert = hartree2ev
force_convert = energy_convert / length_convert

symbols = ['X', 'H', 'He', 'Li', 'Be', 'B', 'C', 'N', 'O', 'F', 'Ne', 'Na', 'Mg', 'Al', 'Si', 'P', 'S', 'Cl', 'Ar', 'K', 'Ca', 'Sc', 'Ti', 'V', 'Cr', 'Mn', 'Fe', 'Co', 'Ni', 'Cu', 'Zn', 'Ga', 'Ge', 'As', 'Se', 'Br', 'Kr', 'Rb', 'Sr', 'Y', 'Zr', 'Nb', 'Mo', 'Tc', 'Ru', 'Rh', 'Pd', 'Ag', 'Cd', 'In', 'Sn', 'Sb', 'Te', 'I', 'Xe', 'Cs', 'Ba', 'La', 'Ce', 'Pr', 'Nd', 'Pm', 'Sm', 'Eu', 'Gd', 'Tb', 'Dy', 'Ho', 'Er', 'Tm', 'Yb', 'Lu', 'Hf', 'Ta', 'W', 'Re', 'Os', 'Ir', 'Pt', 'Au', 'Hg', 'Tl', 'Pb', 'Bi', 'Po', 'At', 'Rn', 'Fr', 'Ra', 'Ac', 'Th', 'Pa', 'U', 'Np', 'Pu', 'Am', 'Cm', 'Bk', 'Cf', 'Es', 'Fm', 'Md', 'No', 'Lr', 'Rf', 'Db', 'Sg', 'Bh', 'Hs', 'Mt', 'Ds', 'Rg', 'Cn', 'Nh', 'Fl', 'Mc', 'Lv', 'Ts', 'Og']

def to_system_data(file_name):
data = {}
# read from log lines
flag = 0
energy = 0
coords = []
atom_symbols = []
forces = []

with open(file_name) as fp:
for line in fp:
if line.startswith(" SCF Done"):
# energies
energy = float(line.split()[4])
elif line.startswith(" Center Atomic Forces (Hartrees/Bohr)"):
flag = 1
elif line.startswith(" Input orientation:"):
flag = 5

if 1 <= flag <= 3 or 5 <= flag <= 9:
flag += 1
elif flag == 4:
# forces
if line.startswith(" -------"):
flag = 0
else:
s = line.split()
forces.append([float(x) for x in s[2:5]])
elif flag == 10:
# atom_symbols and coords
if line.startswith(" -------"):
flag = 0
else:
s = line.split()
coords.append([float(x) for x in s[3:6]])
atom_symbols.append(symbols[int(s[1])])

assert(coords), "cannot find coords"
assert(energy), "cannot find energies"
assert(forces), "cannot find forces"

atom_names, data['atom_types'], atom_numbs = np.unique(atom_symbols, return_inverse=True, return_counts=True)
data['atom_names'] = list(atom_names)
data['atom_numbs'] = list(atom_numbs)
data['forces'] = np.array([forces]) * force_convert
data['energies'] = np.array([energy]) * energy_convert
data['coords'] = np.array([coords])
return data
10 changes: 10 additions & 0 deletions dpdata/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import dpdata.deepmd.comp
import dpdata.pwscf.traj
import dpdata.md.pbc
import dpdata.gaussian.log

class System (object) :
'''
Expand Down Expand Up @@ -282,6 +283,7 @@ def __init__ (self,
- ``deepmd/raw``: deepmd-kit raw
- ``deepmd/npy``: deepmd-kit compressed format (numpy binary)
- ``pwscf/traj``: pwscf trajectory files. should have: file_name+'.in', file_name+'.pos', file_name+'.evp' and file_name+'.for'
- ``gaussian/log``: gaussian logs

type_map : list of str
Needed by formats deepmd/raw and deepmd/npy. Maps atom type to name. The atom with type `ii` is mapped to `type_map[ii]`.
Expand All @@ -308,6 +310,8 @@ def __init__ (self,
self.from_deepmd_comp(file_name, type_map = type_map)
elif fmt == 'pwscf/traj':
self.from_pwscf_traj(file_name, begin = begin, step = step)
elif fmt == 'gaussian/log':
self.from_gaussian_log(file_name)
else :
raise RuntimeError('unknow data format ' + fmt)

Expand Down Expand Up @@ -433,6 +437,12 @@ def from_pwscf_traj(self, prefix, begin = 0, step = 1) :
self.rot_lower_triangular()


def from_gaussian_log(self, file_name):
self.data = dpdata.gaussian.log.to_system_data(file_name)
self.data['cells'] = np.array([[[100., 0., 0.], [0., 100., 0.], [0., 0., 100.]]])
self.data['virials'] = []


def sub_system(self, f_idx) :
"""
Construct a subsystem from the system
Expand Down
Loading