Skip to content

Commit

Permalink
Relocated get_xyz_string and get_xyz_matrix
Browse files Browse the repository at this point in the history
From Species to Parser
to avoid circular import (plus, it makes sense)
  • Loading branch information
alongd committed Feb 25, 2019
1 parent 34a29f5 commit ece9170
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 80 deletions.
77 changes: 77 additions & 0 deletions arc/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import numpy as np
import os

from rmgpy.molecule.element import getElement
from arkane.statmech import Log

from arc.exceptions import InputError
Expand Down Expand Up @@ -72,6 +73,82 @@ def parse_e0(path):
return e0


def get_xyz_string(xyz, mol=None, number=None, symbol=None):
"""
Convert list of lists xyz form:
[[0.6616514836, 0.4027481525, -0.4847382281],
[-0.6039793084, 0.6637270105, 0.0671637135],
[-1.4226865648, -0.4973210697, -0.2238712255],
[-0.4993010635, 0.6531020442, 1.0853092315],
[-2.2115796924, -0.4529256762, 0.4144516252],
[-1.8113671395, -0.3268900681, -1.1468957003]]
into a geometry form read by ESS:
C 0.6616514836 0.4027481525 -0.4847382281
N -0.6039793084 0.6637270105 0.0671637135
H -1.4226865648 -0.4973210697 -0.2238712255
H -0.4993010635 0.6531020442 1.0853092315
H -2.2115796924 -0.4529256762 0.4144516252
H -1.8113671395 -0.3268900681 -1.1468957003
The atom symbol is derived from either an RMG Molecule object (`mol`) or atom numbers ('number`)
or explicitly given (`symbol`).
`number` and `symbol` are lists (optional parameters)
`xyz` is an array of arrays, as shown in the example above.
This function isn't defined as a method of ARCSpecies since it is also used when parsing opt geometry in Scheduler
"""
result = ''
if symbol is not None:
elements = symbol
elif number is not None:
elements = []
for num in number:
elements.append(getElement(int(num)).symbol)
elif mol is not None:
elements = []
for atom in mol.atoms:
elements.append(atom.element.symbol)
else:
raise ValueError("Must have either an RMG:Molecule object input as `mol`, or atomic numbers \ symbols.")
for i, coord in enumerate(xyz):
result += elements[i] + ' ' * (4 - len(elements[i]))
for c in coord:
result += '{0:14.8f}'.format(c)
result += '\n'
return result


def get_xyz_matrix(xyz):
"""
Convert a string xyz form:
C 0.6616514836 0.4027481525 -0.4847382281
N -0.6039793084 0.6637270105 0.0671637135
H -1.4226865648 -0.4973210697 -0.2238712255
H -0.4993010635 0.6531020442 1.0853092315
H -2.2115796924 -0.4529256762 0.4144516252
H -1.8113671395 -0.3268900681 -1.1468957003
into a list of lists xyz form:
[[0.6616514836, 0.4027481525, -0.4847382281],
[-0.6039793084, 0.6637270105, 0.0671637135],
[-1.4226865648, -0.4973210697, -0.2238712255],
[-0.4993010635, 0.6531020442, 1.0853092315],
[-2.2115796924, -0.4529256762, 0.4144516252],
[-1.8113671395, -0.3268900681, -1.1468957003]]
Returns xyz as well as atoms, x, y, z seperately
"""
x, y, z, atoms = [], [], [], []
for line in xyz.split('\n'):
if line:
atom, xx, yy, zz = line.split()
x.append(float(xx))
y.append(float(yy))
z.append(float(zz))
atoms.append(atom)
xyz = []
for i, _ in enumerate(x):
xyz.append([x[i], y[i], z[i]])
return xyz, atoms, x, y, z


def parse_xyz_from_file(path):
"""
Parse xyz coordinated from:
Expand Down
3 changes: 2 additions & 1 deletion arc/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
from rmgpy.quantity import ScalarQuantity
from rmgpy.species import Species

from arc.species import ARCSpecies, mol_from_xyz, get_xyz_matrix, rdkit_conf_from_mol
from arc.species import ARCSpecies, mol_from_xyz, rdkit_conf_from_mol
from arc.parser import get_xyz_matrix
from arc.exceptions import InputError


Expand Down
3 changes: 2 additions & 1 deletion arc/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@
import arc.rmgdb as rmgdb
from arc import plotter
from arc import parser
from arc.parser import get_xyz_string
from arc.species import determine_rotor_symmetry
from arc.job.job import Job
from arc.exceptions import SpeciesError, SchedulerError
from arc.job.ssh import SSH_Client
from arc.species import ARCSpecies, TSGuess, get_xyz_string
from arc.species import ARCSpecies, TSGuess
from arc.ts.atst import autotst
from arc.settings import rotor_scan_resolution, inconsistency_ab, inconsistency_az, maximum_barrier

Expand Down
76 changes: 0 additions & 76 deletions arc/species.py
Original file line number Diff line number Diff line change
Expand Up @@ -1184,82 +1184,6 @@ def find_internal_rotors(mol):
return rotors


def get_xyz_string(xyz, mol=None, number=None, symbol=None):
"""
Convert list of lists xyz form:
[[0.6616514836, 0.4027481525, -0.4847382281],
[-0.6039793084, 0.6637270105, 0.0671637135],
[-1.4226865648, -0.4973210697, -0.2238712255],
[-0.4993010635, 0.6531020442, 1.0853092315],
[-2.2115796924, -0.4529256762, 0.4144516252],
[-1.8113671395, -0.3268900681, -1.1468957003]]
into a geometry form read by ESS:
C 0.6616514836 0.4027481525 -0.4847382281
N -0.6039793084 0.6637270105 0.0671637135
H -1.4226865648 -0.4973210697 -0.2238712255
H -0.4993010635 0.6531020442 1.0853092315
H -2.2115796924 -0.4529256762 0.4144516252
H -1.8113671395 -0.3268900681 -1.1468957003
The atom symbol is derived from either an RMG Molecule object (`mol`) or atom numbers ('number`)
or explicitly given (`symbol`).
`number` and `symbol` are lists (optional parameters)
`xyz` is an array of arrays, as shown in the example above.
This function isn't defined as a method of ARCSpecies since it is also used when parsing opt geometry in Scheduler
"""
result = ''
if symbol is not None:
elements = symbol
elif number is not None:
elements = []
for num in number:
elements.append(getElement(int(num)).symbol)
elif mol is not None:
elements = []
for atom in mol.atoms:
elements.append(atom.element.symbol)
else:
raise ValueError("Must have either an RMG:Molecule object input as `mol`, or atomic numbers \ symbols.")
for i, coord in enumerate(xyz):
result += elements[i] + ' ' * (4 - len(elements[i]))
for c in coord:
result += '{0:14.8f}'.format(c)
result += '\n'
return result


def get_xyz_matrix(xyz):
"""
Convert a string xyz form:
C 0.6616514836 0.4027481525 -0.4847382281
N -0.6039793084 0.6637270105 0.0671637135
H -1.4226865648 -0.4973210697 -0.2238712255
H -0.4993010635 0.6531020442 1.0853092315
H -2.2115796924 -0.4529256762 0.4144516252
H -1.8113671395 -0.3268900681 -1.1468957003
into a list of lists xyz form:
[[0.6616514836, 0.4027481525, -0.4847382281],
[-0.6039793084, 0.6637270105, 0.0671637135],
[-1.4226865648, -0.4973210697, -0.2238712255],
[-0.4993010635, 0.6531020442, 1.0853092315],
[-2.2115796924, -0.4529256762, 0.4144516252],
[-1.8113671395, -0.3268900681, -1.1468957003]]
Returns xyz as well as atoms, x, y, z seperately
"""
x, y, z, atoms = [], [], [], []
for line in xyz.split('\n'):
if line:
atom, xx, yy, zz = line.split()
x.append(float(xx))
y.append(float(yy))
z.append(float(zz))
atoms.append(atom)
xyz = []
for i, _ in enumerate(x):
xyz.append([x[i], y[i], z[i]])
return xyz, atoms, x, y, z


def determine_occ(label, xyz, charge):
"""
Determines the number of occupied orbitals for an MRCI calculation
Expand Down
3 changes: 2 additions & 1 deletion arc/speciesTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
from rmgpy.species import Species
from rmgpy.reaction import Reaction

from arc.species import ARCSpecies, TSGuess, get_xyz_string, get_xyz_matrix, mol_from_xyz, check_xyz,\
from arc.species import ARCSpecies, TSGuess, mol_from_xyz, check_xyz,\
determine_rotor_type, determine_rotor_symmetry
from arc.parser import get_xyz_string, get_xyz_matrix
from arc.settings import arc_path

################################################################################
Expand Down
2 changes: 1 addition & 1 deletion arc/ts/run_autotst.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from autotst.reaction import AutoTST_Reaction

from arc.species import get_xyz_string
from arc.parser import get_xyz_string
from arc.exceptions import TSError
from arc.settings import arc_path

Expand Down

0 comments on commit ece9170

Please sign in to comment.