From ecf13b05a53771e7a70a1ff2f5674d1d646cd393 Mon Sep 17 00:00:00 2001 From: alongd Date: Mon, 25 Feb 2019 13:23:09 -0500 Subject: [PATCH] Relocated get_xyz_string and get_xyz_matrix From Species to Parser to avoid circular import (plus, it makes sense) --- arc/parser.py | 77 +++++++++++++++++++++++++++++++++++++++++++ arc/plotter.py | 3 +- arc/scheduler.py | 3 +- arc/species.py | 76 ------------------------------------------ arc/speciesTest.py | 3 +- arc/ts/run_autotst.py | 2 +- 6 files changed, 84 insertions(+), 80 deletions(-) diff --git a/arc/parser.py b/arc/parser.py index 0f51ddbe36..ec1f86dfe6 100644 --- a/arc/parser.py +++ b/arc/parser.py @@ -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 @@ -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: diff --git a/arc/plotter.py b/arc/plotter.py index a883608e18..8051e12ea8 100644 --- a/arc/plotter.py +++ b/arc/plotter.py @@ -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 diff --git a/arc/scheduler.py b/arc/scheduler.py index 793cc6b24b..6e8134d961 100644 --- a/arc/scheduler.py +++ b/arc/scheduler.py @@ -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 diff --git a/arc/species.py b/arc/species.py index 40ecd05567..3cb0e24858 100644 --- a/arc/species.py +++ b/arc/species.py @@ -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 diff --git a/arc/speciesTest.py b/arc/speciesTest.py index a0ce8e4ee4..a4fc37c66a 100644 --- a/arc/speciesTest.py +++ b/arc/speciesTest.py @@ -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 ################################################################################ diff --git a/arc/ts/run_autotst.py b/arc/ts/run_autotst.py index 82d3474d6e..8970e29bf6 100644 --- a/arc/ts/run_autotst.py +++ b/arc/ts/run_autotst.py @@ -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