Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update frequency parsing in Gaussian #232

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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
32 changes: 5 additions & 27 deletions electronicparsers/gaussian/metainfo/gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,45 +603,23 @@ class x_gaussian_section_frequencies(MSection):
validate=False,
)

x_gaussian_frequency_values = Quantity(
type=str,
shape=['number_of_frequency_rows'],
description="""
values of frequencies, in cm-1
""",
)

x_gaussian_frequencies = Quantity(
type=np.float64,
unit='1/m',
shape=['number_of_frequencies'],
description="""
values of frequencies, in cm-1
values of frequencies
""",
)

x_gaussian_reduced_masses = Quantity(
type=np.float64,
shape=['number_of_reduced_masses_rows'],
description="""
values of normal mode reduced masses
""",
)
) # only store the '--' header, not '---'

x_gaussian_red_masses = Quantity(
type=np.float64,
unit='kg',
shape=['number_of_frequencies'],
description="""
values of normal mode reduced masses
""",
)

x_gaussian_normal_modes = Quantity(
type=str,
shape=['number_of_normal_modes_rows'],
description="""
normal mode vectors
""",
)
) # only store the '--' header, not '---'

x_gaussian_normal_mode_values = Quantity(
type=np.float64,
Expand Down
55 changes: 44 additions & 11 deletions electronicparsers/gaussian/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,25 @@ def str_to_force_constants(val_in):
fc = fc + fc.T - np.diag(fc.diagonal())
return fc

def str_to_units(unit: str):
ndaelman-hu marked this conversation as resolved.
Show resolved Hide resolved
"""Map native Gaussian units to pint units.
Assumes lower case string input.""" # TODO handle compound units recursively
unit = unit.lower()
if unit == 'cm**-1':
return ureg.cm_1
elif unit == 'ghz':
return ureg.gigahertz
elif unit == 'kcal/mol':
return ureg.kilocalorie / ureg.mole
elif unit == 'kj/mol':
return ureg.kilojoule / ureg.mole
elif unit == 'j':
return ureg.joule
elif unit == 'amu':
return ureg.amu
else:
raise ValueError(f'Unknown unit {unit}')

orientation_quantities = [
Quantity(
'standard_orientation',
Expand Down Expand Up @@ -391,14 +410,27 @@ def str_to_force_constants(val_in):
unit='debye * angstrom**3',
),
Quantity(
'frequencies', r'\n *Frequencies \-\-\s*(.+)', dtype=float, repeats=True
'frequency_unit',
r'[Hh]armonic frequencies \((\S+)\)',
str_operation=str_to_units,
),
Quantity(
'reduced_mass_unit',
r'reduced masses \((\S+)\)',
str_operation=str_to_units,
),
Quantity(
'frequencies',
r'\n *Frequencies [\-]{2}\s+(.+)',
dtype=float,
repeats=True,
), # note the mandatory space after the '--'. Use nested strategy if space is optional
Quantity(
'reduced_masses',
r'\n *Red\. masses \-\-\s*(.+)',
r'\n *Red\. masses [\-]{2}\s+(.+)',
str_operation=lambda x: [float(v) for v in x.split()],
repeats=True,
),
), # note the mandatory space after the '--'. Use nested strategy if space is optional
Quantity(
'normal_modes',
r'Atom\s*AN.*\s*([\-\d\s\.]+)',
Expand Down Expand Up @@ -1106,18 +1138,19 @@ def parse_energy_corrections(method, iteration=False):
# vibrational frequencies
frequencies = section.get('frequencies')
if frequencies is not None:
# frequencies in old parsers are in J, not consistent with metainfo
sec_frequencies = x_gaussian_section_frequencies()
sec_run.x_gaussian_section_frequencies.append(sec_frequencies)
sec_frequencies.x_gaussian_frequencies = np.hstack(frequencies)

sec_frequencies.x_gaussian_frequencies = np.hstack(
frequencies
) * section.get('frequency_unit', ureg.cm_1)

reduced_masses = section.get('reduced_masses')
if reduced_masses is not None:
reduced_masses = (
np.array(np.hstack(reduced_masses), dtype=np.float64) * ureg.amu
)
sec_frequencies.x_gaussian_red_masses = reduced_masses.to(
'kg'
).magnitude
sec_frequencies.x_gaussian_red_masses = np.hstack(
reduced_masses
) * section.get('reduced_mass_unit', ureg.amu)

normal_modes = section.get('normal_modes')
if normal_modes is not None:
normal_modes = np.hstack(normal_modes)
Expand Down
Loading