Skip to content

Commit

Permalink
Added charge definition for Extended Huckel
Browse files Browse the repository at this point in the history
  • Loading branch information
abelcarreras committed Apr 21, 2022
1 parent 85d52e8 commit 61d5c42
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 28 deletions.
35 changes: 25 additions & 10 deletions cosymlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@

from cosymlib.molecule import Molecule
from cosymlib.molecule.geometry import Geometry
from cosymlib import file_io
from cosymlib import tools
from cosymlib.molecule.electronic_structure import ElectronicStructure
from cosymlib.molecule.electronic_structure import ProtoElectronicDensity
from cosymlib.molecule.electronic_structure import ProtoElectronicStructure
from cosymlib.simulation import ExtendedHuckel
from cosymlib.utils import swap_vectors
from cosymlib.utils import get_shape_path, plot_molecular_orbital_diagram, plot_symmetry_energy_evolution
from cosymlib.shape.tools import get_structure_references, get_sym_from_label
import matplotlib.pyplot as plt
from cosymlib import file_io
from cosymlib import tools
from warnings import warn

import matplotlib.pyplot as plt
import numpy as np
import sys
import os
import numpy as np


def _get_symmetry_arguments(locals):
Expand Down Expand Up @@ -102,16 +106,27 @@ def __init__(self,
ignore_connectivity=False,
connectivity=None,
connectivity_thresh=None,
charge_eh=0,
mode=0):

mode_list = [None, 'EH', 'Dens']
self._mode = mode_list[mode]
def get_electronic_structure(structure):
if mode == 0:
return None
elif mode == 1:
return ExtendedHuckel(structure, charge=charge_eh)
elif mode == 2:
protodensity = ProtoElectronicDensity(structure)
return ProtoElectronicStructure(basis=protodensity.get_basis(),
orbital_coefficients=[protodensity.get_mo_coefficients(),[]])
else:
raise Exception('Mode {} not available'.format(mode))

self._molecules = []
if isinstance(structures, (list, tuple)):
for structure in structures:
self._molecules.append(Molecule(structure, electronic_structure=self._mode))
self._molecules.append(Molecule(structure, electronic_structure=get_electronic_structure(structure)))
else:
self._molecules.append(Molecule(structures, electronic_structure=self._mode))
self._molecules.append(Molecule(structures, electronic_structure=get_electronic_structure(structures)))

for molecule in self._molecules:
if ignore_atoms_labels:
Expand Down Expand Up @@ -394,7 +409,7 @@ def _print_electronic_symmetry_measure(self, group, axis=None, axis2=None, cente
txt += '\n'
txt += sep_line

txt += '{:<9} '.format(molecule.name) + ' '.join(['{:7.3f}'.format(s) for s in wf_measure['csm']])
txt += '{:<9} '.format(molecule.name)[:9] + ' '.join(['{:7.3f}'.format(s) for s in wf_measure['csm']])
txt += '\n'
first = False

Expand Down Expand Up @@ -430,7 +445,7 @@ def print_edensity_measure(self, group, axis=None, axis2=None, center=None, outp
txt += '\n'
txt += sep_line

txt += '{:<9} '.format(molecule.name) + ' '.join(['{:7.3f}'.format(s) for s in dens_measure['csm_coef']])
txt += '{:<9} '.format(molecule.name)[:9] + ' '.join(['{:7.3f}'.format(s) for s in dens_measure['csm_coef']])
txt += '\n\n'


Expand Down
23 changes: 8 additions & 15 deletions cosymlib/molecule/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#from cosymlib.molecule.geometry import Geometry
#from cosymlib.molecule.electronic_structure import ProtoElectronicDensity
#from cosymlib.molecule.electronic_structure import ProtoElectronicStructure
from cosymlib.molecule.electronic_structure import ElectronicStructure
from cosymlib.molecule.electronic_structure import ProtoElectronicDensity
from cosymlib.molecule.electronic_structure import ProtoElectronicStructure
from cosymlib.molecule.geometry import Geometry
from cosymlib.simulation import ExtendedHuckel
from cosymlib.tools import element_to_atomic_number
from warnings import warn
Expand Down Expand Up @@ -29,7 +29,8 @@ class Molecule:
:type name: str
"""
def __init__(self, geometry,
def __init__(self,
geometry,
electronic_structure=None,
name=None):

Expand Down Expand Up @@ -77,17 +78,9 @@ def electronic_structure(self):

# if None default electronic structure is ExtendedHuckel
if self._electronic_structure is None:
self._electronic_structure = 'EH'
warn('Electronic structure auto generated from Extended-Huckel calculation')

if self._electronic_structure == 'EH':
warn('Electronic structure auto generated from Extended-Huckel calculation with charge=0')
self._electronic_structure = ExtendedHuckel(self.geometry)

elif self._electronic_structure == 'Dens':
protodensity = ProtoElectronicDensity(self.geometry)
self._electronic_structure = ProtoElectronicStructure(basis=protodensity.get_basis(),
orbital_coefficients=[protodensity.get_mo_coefficients(),[]])

return self._electronic_structure

# TODO: 'symmetry' and 'shape' properties may be removed. All methods inside these
Expand Down Expand Up @@ -183,8 +176,8 @@ def get_charge(self):
"""
Get the charge of the molecule
"""
if self._electronic_structure is None:
return None
#if self._electronic_structure is None:
# return None
net_electrons = sum([element_to_atomic_number(symbol) for symbol in self.get_symbols()])
return net_electrons - (sum(self.electronic_structure.alpha_occupancy) +
sum(self.electronic_structure.beta_occupancy))
15 changes: 13 additions & 2 deletions scripts/esym
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env python
import warnings

from cosymlib import Cosymlib, __version__
from cosymlib.file_io.tools import print_header, print_footer, print_input_info
from cosymlib.file_io import read_generic_structure_file
Expand Down Expand Up @@ -56,7 +58,13 @@ parser.add_argument('--mode',
metavar='I',
type=int,
default=0,
help='working mode. Check manual for further details (default:0) ')
help='working mode. Check manual for further details (default:0)')
parser.add_argument('--charge',
dest='charge',
metavar='I',
type=int,
default=0,
help='Charge in Extended Huckel calculations default:0)')
parser.add_argument('-center',
dest='center',
metavar='R',
Expand Down Expand Up @@ -105,9 +113,12 @@ common_output = open(args.output_name, 'w') if args.output_name is not None else
if args.input_file is None:
parser.error('No input file selected! An existing file must be provide')

if args.charge != 0 and args.mode != 1:
warnings.warn('Charge only works in mode 1. For other modes it will be ignored')

print_header(common_output)
structures = read_generic_structure_file(args.input_file, read_multiple=True)
structure_set = Cosymlib(structures, mode=args.mode)
structure_set = Cosymlib(structures, mode=args.mode, charge_eh=args.charge)

if args.labels:
print_symmetry_labels()
Expand Down
14 changes: 13 additions & 1 deletion scripts/mosym
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ parser.add_argument('--mo_overlaps',
help='print the molecular orbitals overlap')

# Modifiers
parser.add_argument('--mode',
dest='mode',
metavar='I',
type=int,
default=0,
help='working mode. Check manual for further details (default:0) ')
parser.add_argument('--charge',
dest='charge',
metavar='I',
type=int,
default=0,
help='Charge in Extended Huckel calculations default:0) ')
parser.add_argument('-center',
dest='center',
metavar='R',
Expand Down Expand Up @@ -123,7 +135,7 @@ if args.input_file is None:

print_header(common_output)
structures = read_generic_structure_file(args.input_file, read_multiple=True)
structure_set = Cosymlib(structures)
structure_set = Cosymlib(structures, mode=args.mode, charge_eh=args.charge)

if args.labels:
print_symmetry_labels()
Expand Down

0 comments on commit 61d5c42

Please sign in to comment.