Skip to content

Commit

Permalink
preliminar integration of posym for geometric symmetry
Browse files Browse the repository at this point in the history
  • Loading branch information
abelcarreras committed Oct 8, 2023
1 parent a8e7879 commit 36797b7
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 47 deletions.
19 changes: 10 additions & 9 deletions cosymlib/__init__.py
Expand Up @@ -149,18 +149,19 @@ def _get_table_format_permutation(labels, molecules_names, permutation):

def _get_table_format_gsym(molecules_names, csm_list, permutation_list, axis_list, precision=3):

txt = ' CSM '+ (2*precision)*' '+ 'Symmetry axis (x,y,z) '+ ' '*(1*precision) + 'permutation\n\n'
width = precision + 4
txt = ' '* 15 + '{:^{width}} {:^{width_2}} {:^20}\n\n'.format('CSM ', 'Symmetry axis (x,y,z) ', 'permutation',
width=width,
width_2=width * 3 + 3)

for idx, name in enumerate(molecules_names):

max_name = len(max(name, key=len))
txt += '{} '.format(name)
if max_name < 9:
n = 18 - len(name)
else:
n = 9 + max_name - len(name)

txt += '{:{width}.{prec}f} '.format(csm_list[idx], width=n, prec=precision) + \
' {:.{prec}f} {:.{prec}f} {:.{prec}f}'.format(*axis_list[idx], width=n, prec=precision) + \
txt += '{:12} '.format(name)
txt += '{:{width}.{prec}f} '.format(csm_list[idx], width=width, prec=precision) + \
' {:{width}.{prec}f} {:{width}.{prec}f} {:{width}.{prec}f}'.format(*axis_list[idx],
width=width,
prec=precision) + \
' {}\n'.format(permutation_list[idx])

return txt
Expand Down
75 changes: 38 additions & 37 deletions cosymlib/symmetry/__init__.py
@@ -1,7 +1,7 @@
from cosymlib.molecule.electronic_structure import ElectronicStructure
from cosymlib.molecule.electronic_structure import ProtoElectronicStructure
from wfnsympy import WfnSympy
from symgroupy import Symgroupy
from posym import SymmetryMolecule
from collections import namedtuple
import numpy as np
import warnings
Expand Down Expand Up @@ -101,41 +101,21 @@ def set_electronic_structure(self, electronic_structure):

def _get_symgroup_results(self, group):

"""
# Temporal interface
if central_atom is not None:
self._central_atom = central_atom
self._multi = multi
self._center = center
self._connect_thresh = connect_thresh
"""

# patch for permutations
if self._permutation is not None and group.lower() not in ['cs', 'ci', 'c1']:
warnings.warn('Custom permutation for this group is not implemented')
if self._permutation is not None:
warnings.warn('Custom permutation is not implemented')
self._permutation = None

# Crude calculation call methods
key = _get_key_symgroup(group, self._center, self._central_atom, self._connectivity, self._multi,
self._connect_thresh, self._permutation)

if key not in self._results:
self._results[key] = Symgroupy(self._coordinates,
group=group,
labels=self._symbols,
central_atom=self._central_atom,
multi=self._multi,
center=self._center,
connectivity=self._connectivity,
connect_thresh=self._connect_thresh,
permutation=self._permutation)

permu = self._results[key].optimum_permutation
key_2 = _get_key_symgroup(group, self._center, self._central_atom, self._connectivity, self._multi,
self._connect_thresh, permu)

self._results[key_2] = self._results[key]
self._results[key] = SymmetryMolecule(group=group,
coordinates=self._coordinates,
symbols=self._symbols,
orientation_angles=None,
center=self._center)
return self._results[key]

def _get_wfnsym_results(self, group):
Expand Down Expand Up @@ -221,7 +201,7 @@ def measure(self, label):
:return: The measure
:rtype: float
"""
return self._get_symgroup_results(label).csm
return self._get_symgroup_results(label).measure

def nearest_structure(self, label):
"""
Expand All @@ -234,7 +214,7 @@ def nearest_structure(self, label):
"""
# TODO: Improve this docstring

return self._get_symgroup_results(label).nearest_structure
return self._get_symgroup_results(label).symmetrized_coordinates

def optimum_axis(self, label):
"""
Expand All @@ -245,7 +225,15 @@ def optimum_axis(self, label):
:return: The axis
:rtype: list
"""
return self._get_symgroup_results(label).optimum_axis
sm = self._get_symgroup_results(label)
for operation in sm.get_oriented_operations():
try:

return operation.axis
except AttributeError:
pass

return [0, 0, 0]

def optimum_permutation(self, label):
"""
Expand All @@ -255,7 +243,10 @@ def optimum_permutation(self, label):
:return: The permutation
:rtype: list
"""
return self._get_symgroup_results(label).optimum_permutation
sm = self._get_symgroup_results(label)
op = sm.get_oriented_operations()[1]
permu = op._get_permutation(op.operation_matrix_list[0], self._coordinates, self._symbols)
return list(np.array(permu) + 1)

def reference_axis(self, label):
"""
Expand All @@ -266,7 +257,13 @@ def reference_axis(self, label):
:return: The axis
:rtype: list
"""
return self._get_symgroup_results(label).reference_axis
sm = self._get_symgroup_results(label)
for operation in sm.get_oriented_operations():
try:
return operation.axis
except AttributeError:
pass
return [[0, 0, 0]]

def csm_multi(self, label, multi=1):
"""
Expand All @@ -279,8 +276,7 @@ def csm_multi(self, label, multi=1):
:return: The measures
:rtype: list
"""
self._multi = multi
return self._get_symgroup_results(label).csm_multi
return [self._get_symgroup_results(label).measure]

def axis_multi(self, label, multi=1):
"""
Expand All @@ -293,8 +289,13 @@ def axis_multi(self, label, multi=1):
:return: List of axis
:rtype: list
"""
self._multi = multi
return self._get_symgroup_results(label).axis_multi
sm = self._get_symgroup_results(label)
for operation in sm.get_oriented_operations():
try:
return operation.axis
except AttributeError:
pass
return [[0, 0, 0]]

##########################################
# Electronic symmetry methods #
Expand Down
2 changes: 1 addition & 1 deletion examples/symmetry/multiple_symmetry.py
Expand Up @@ -8,7 +8,7 @@
# the eclipsed and the staggered forms. The first thing to do is to read the xyz file that contains the molecules and
# creates one or multiple Geometry objects which will storage all the structural information

structures = get_geometry_from_file_xyz('../Symgroup/ethane.xyz', read_multiple=True)
structures = get_geometry_from_file_xyz('../data/ethane.xyz', read_multiple=True)

# Now we are going to create a Cosymlib object with all these Geometry objects to simplify the printing process

Expand Down

0 comments on commit 36797b7

Please sign in to comment.