Skip to content

Commit

Permalink
Conform code to consistent implementation philosophy
Browse files Browse the repository at this point in the history
Removal of global logic, inplace, update_structure etc
Ensure __copy__ methods work as intended
Unify `to_xyz` and `to_xyzblock`
Remove `downgrade_to_xyz`
  • Loading branch information
smcolby committed Aug 17, 2023
1 parent 87e1566 commit ea3b414
Show file tree
Hide file tree
Showing 10 changed files with 717 additions and 610 deletions.
8 changes: 4 additions & 4 deletions isicle/adducts.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def set_charge(self):
'''

if self.geom.__dict__.get('charge') is None:
self.geom.__dict__.update(charge=self.geom.get_formal_charge())
self.geom.__dict__.update(charge=self.geom.get_charge())

def _set_ions(self, ion_path=None, ion_list=None):
'''
Expand Down Expand Up @@ -472,7 +472,7 @@ def _update_geometry_charge(self, geom):
'''
'''

geom.__dict__.update(charge=geom.get_formal_charge())
geom.__dict__.update(charge=geom.get_charge())

def _add_ion(self, init_mol, base_atom_idx, ion_atomic_num, sanitize, forcefield, ff_iter):
'''
Expand Down Expand Up @@ -983,9 +983,9 @@ def set_charge(self):
if self.geom.load.get('filetype') == '.xyz':
# self.geom.__dict__.update(charge=charge)
raise ValueError(
'Must first run geom.set_formal_charge for an xyz structure')
'Must first run geom.set_charge for an xyz structure')
else:
self.geom.__dict__.update(charge=self.geom.get_formal_charge())
self.geom.__dict__.update(charge=self.geom.get_charge())

def _set_ions(self, ion_path=None, ion_list=None):
cations, anions, complex = _parse_ions(
Expand Down
14 changes: 14 additions & 0 deletions isicle/conformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,9 @@ def __init__(self, *args):
----------
*args
Objects to comprise the conformational ensemble.
'''

super().__init__((Geometry, XYZGeometry), *args)

def _check_attributes(self, attr):
Expand All @@ -395,7 +397,9 @@ def _check_attributes(self, attr):
------
AttributeError
If all members do not have `attr`.
'''

value = [x.get___dict__() for x in self]
for key in safelist(attr):
if not all(key in x for x in value):
Expand All @@ -421,7 +425,9 @@ def reduce(self, attr, func='boltzmann', **kwargs):
-------
:obj:`~pandas.DataFrame`
Result of reduction operation.
'''

# Select reduction function
f = _function_selector(func)

Expand Down Expand Up @@ -493,7 +499,9 @@ def _apply_method(self, method, **kwargs):
-------
:obj:`~isicle.conformers.ConformationalEnsemble` or list
Result of operation, type depends on `method` return type.
'''

# Check for attribute
if not all(hasattr(x, method) for x in self):
raise AttributeError('"{}" not found for all conformational '
Expand Down Expand Up @@ -525,7 +533,9 @@ def _apply_function(self, func, **kwargs):
-------
:obj:`~isicle.conformers.ConformationalEnsemble` or list
Result of operation, type depends on `func` return type.
'''

# Apply method to collection
result = [func(x, **kwargs) for x in self]

Expand Down Expand Up @@ -560,7 +570,9 @@ def apply(self, func=None, method=None, **kwargs):
------
ValueError
If neither `func` nor `method` is supplied.
'''

# Apply function
if func is not None:
return self._apply_function(func, **kwargs)
Expand All @@ -579,7 +591,9 @@ def get_structures(self):
-------
:obj:`~isicle.conformers.ConformationalEnsemble`
Conformational ensemble.
'''

# Check for geom attribute
self._check_attributes('geom')

Expand Down
Loading

0 comments on commit ea3b414

Please sign in to comment.