Skip to content

Commit

Permalink
minor cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
abelcarreras committed Mar 9, 2021
1 parent 07c374f commit a244399
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 37 deletions.
42 changes: 19 additions & 23 deletions cosymlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ def _get_table_format(labels, molecules_names, data):
return txt


def _get_axis_info(molecule, group, axis, axis2, center):

txt = ''
axis_info = molecule.get_symmetry_axes(group, axis=axis, axis2=axis2, center=center)
txt += '\nSymmetry axis orientation\n'
txt += 'center: ' + ' '.join(['{:12.8f}'.format(s) for s in axis_info['center']])
txt += '\n'
txt += 'axis : ' + ' '.join(['{:12.8f}'.format(s) for s in axis_info['axis']])
txt += '\n'
txt += 'axis2 : ' + ' '.join(['{:12.8f}'.format(s) for s in axis_info['axis2']])
txt += '\n'
return txt


class Cosymlib:
"""
Main cosymlib class
Expand Down Expand Up @@ -336,11 +350,6 @@ def print_chirality_measure(self, labels, central_atom=0, center=None, output=sy

output.write(txt)

# This should be substituted by calling methods within this class
def OLD_print_wnfsym_measure_verbose(self, group, axis=None, axis2=None, center=None, output=sys.stdout):
self.print_wnfsym_sym_matrices(group, axis=axis, axis2=axis2, center=center, output=output)
self.print_wnfsym_irreducible_repr(group, axis=axis, axis2=axis2, center=center, output=output)

def _print_electronic_symmetry_measure(self, group, axis=None, axis2=None, center=None, output=sys.stdout):

txt = ''
Expand Down Expand Up @@ -520,7 +529,7 @@ def print_wnfsym_irreducible_repr(self, group, axis=None, axis2=None, center=Non
ir_mo = molecule.get_mo_irreducible_representations(group, axis=axis, axis2=axis2, center=center)
data_wf = molecule.get_wf_irreducible_representations(group, axis=axis, axis2=axis2, center=center)

txt = '\nMolecule : {}\n'.format(molecule.name)
txt += '\nMolecule : {}\n'.format(molecule.name)
sep_line = ' ' + '---------' * (len(ir_mo['labels'])) + '\n'

txt += '\nWaveFunction: Irred. Rep. Decomposition\n'
Expand All @@ -535,14 +544,7 @@ def print_wnfsym_irreducible_repr(self, group, axis=None, axis2=None, center=Non
txt += 'WFN ' + ' '.join(['{:7.3f}'.format(s) for s in data_wf['total']])
txt += '\n'

axes_information = molecule.get_symmetry_axes(group, axis=axis, axis2=axis2, center=center)
txt += '\nSymmetry parameters\n'
txt += 'center: ' + ' '.join(['{:12.8f}'.format(s) for s in axes_information['center']])
txt += '\n'
txt += 'axis : ' + ' '.join(['{:12.8f}'.format(s) for s in axes_information['axis']])
txt += '\n'
txt += 'axis2 : ' + ' '.join(['{:12.8f}'.format(s) for s in axes_information['axis2']])
txt += '\n'
txt += _get_axis_info(molecule, group, axis, axis2, center)

output.write(txt)

Expand All @@ -556,7 +558,7 @@ def print_wnfsym_mo_irreducible_repr(self, group, axis=None, axis2=None, center=
beta_energies = molecule.electronic_structure.beta_energies
beta_occupancy = molecule.electronic_structure.beta_occupancy

txt = '\nMolecule : {}\n'.format(molecule.name)
txt += '\nMolecule : {}\n'.format(molecule.name)

sep_line = ' ' + '---------' * (2 + len(ir_mo['labels'])) + '\n'

Expand Down Expand Up @@ -591,14 +593,8 @@ def print_wnfsym_mo_irreducible_repr(self, group, axis=None, axis2=None, center=

if non_one:
warn('The sum of some molecular orbital irreducible represaentations are not equal one (*)')
axes_information = molecule.get_symmetry_axes(group, axis=axis, axis2=axis2, center=center)
txt += '\nSymmetry parameters\n'
txt += 'center: ' + ' '.join(['{:12.8f}'.format(s) for s in axes_information['center']])
txt += '\n'
txt += 'axis : ' + ' '.join(['{:12.8f}'.format(s) for s in axes_information['axis']])
txt += '\n'
txt += 'axis2 : ' + ' '.join(['{:12.8f}'.format(s) for s in axes_information['axis2']])
txt += '\n'

txt += _get_axis_info(molecule, group, axis, axis2, center)

output.write(txt)

Expand Down
8 changes: 4 additions & 4 deletions cosymlib/molecule/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(self, geometry,
self._symmetry = geometry._symmetry
self._shape = geometry._shape

def molecule_copy(self):
def get_copy(self):
return deepcopy(self)

def set_name(self, name):
Expand Down Expand Up @@ -70,7 +70,7 @@ def electronic_structure(self):
:rtype: ElectronicStructure
"""
if self._electronic_structure is None:
warn('Warning: Electronic structure auto generated from Extended-Huckel calculation')
warn('Electronic structure auto generated from Extended-Huckel calculation')
eh = ExtendedHuckel(self.geometry)
self._electronic_structure = ElectronicStructure(basis=eh.get_basis(),
orbital_coefficients=[eh.get_mo_coefficients(), []],
Expand All @@ -82,8 +82,8 @@ def electronic_structure(self):

return self._electronic_structure

# TODO: 'symmetry' and 'shape' properties should be removed. All methods inside these
# TODO: classes should be mirrored in geometry/molecule class
# TODO: 'symmetry' and 'shape' properties may be removed. All methods inside these
# TODO: classes may be mirrored in geometry/molecule class? [idea]
@property
def symmetry(self):
return self._symmetry
Expand Down
22 changes: 12 additions & 10 deletions cosymlib/molecule/electronic_structure/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
HARTREE_TO_EV = 27.21139563180092


class ElectronicStructure:
"""
Main Electronic structure class
Expand All @@ -10,13 +13,13 @@ class ElectronicStructure:
# :type charge: int
:param multiplicity: The multiplicity
:type multiplicity: int
:param alpha_energies: Alpha molecular orbital energies
:param alpha_energies: Alpha molecular orbital energies in Hartree
:type alpha_energies: list
:param beta_energies: Beta molecular orbital energies
:param beta_energies: Beta molecular orbital energies in Hartree
:type beta_energies: list
:param alpha_occupancy: List of alpha electrons
:param alpha_occupancy: Occupancy of alpha orbitals
:type alpha_occupancy: list
:param beta_occupancy: List of beta electrons
:param beta_occupancy: Occupancy of beta orbitals
:type beta_occupancy: list
"""
Expand All @@ -39,12 +42,11 @@ def __init__(self,
else:
self._Cb = orbital_coefficients[1]

ha_eV = 27.21139563180092
self._alpha_energies = [energy*ha_eV for energy in alpha_energies]
self._alpha_energies = [energy * HARTREE_TO_EV for energy in alpha_energies]
if len(beta_energies) == 0:
self._beta_energies = [energy*ha_eV for energy in alpha_energies]
self._beta_energies = [energy * HARTREE_TO_EV for energy in alpha_energies]
else:
self._beta_energies = [energy*ha_eV for energy in beta_energies]
self._beta_energies = [energy * HARTREE_TO_EV for energy in beta_energies]

self._alpha_occupancy = alpha_occupancy
self._beta_occupancy = beta_occupancy
Expand All @@ -61,14 +63,14 @@ def set_occupancy(self, occupancy):

def set_alpha_occupancy(self, occupancy):
if len(occupancy) > len(self._Ca):
raise IndexError('Lenght of alpha occupancy list is longer than the molecular orbitals provided')
raise IndexError('Alpha occupancy list do not match with molecular orbitals')
self._alpha_occupancy = occupancy
self._occupancy_consistency()
self._recalculate_spin()

def set_beta_occupancy(self, occupancy):
if len(occupancy) > len(self._Cb):
raise IndexError('Lenght of beta occupancy list is longer than the molecular orbitals provided')
raise IndexError('Beta occupancy list do not match with molecular orbitals')
self._beta_occupancy = occupancy
self._occupancy_consistency()
self._recalculate_spin()
Expand Down

0 comments on commit a244399

Please sign in to comment.