Skip to content

Commit

Permalink
Begin overhaul of charge propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
smcolby committed Apr 19, 2024
1 parent b49c201 commit 8b0757f
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 466 deletions.
45 changes: 11 additions & 34 deletions isicle/adducts.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,6 @@ def set_geometry(self, geom):
else:
raise ValueError('Could not find self.mol or self.geom')

def set_charge(self):
'''
'''

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

def _set_ions(self, ion_path=None, ion_list=None):
'''
'''
Expand Down Expand Up @@ -468,6 +461,7 @@ def _forcefield_selector(self, forcefield, mw):
raise ValueError(
'RDKit only supports UFF, MMFF, MMFF94, MMFF94s as forcefields.')

# TODO: update this
def _update_geometry_charge(self, geom):
'''
'''
Expand Down Expand Up @@ -873,9 +867,6 @@ def run(self, geom, ion_path=None, ion_list=None, **kwargs):
# Sets geom to self.geom
self.set_geometry(geom)

# Infers charge of geom.mol
self.set_charge()

# Load specified ions by type
# Validity check if negative ionization can be done
self.configure(ion_path=ion_path, ion_list=ion_list)
Expand Down Expand Up @@ -975,18 +966,6 @@ def set_geometry(self, geom):
else:
raise ValueError('Could not find self.xyz, self.mol, or self.geom')

def set_charge(self):
'''
'''

if self.geom.__dict__.get('charge') is None:
if self.geom.load.get('filetype') == '.xyz':
# self.geom.__dict__.update(charge=charge)
raise ValueError(
'Must first run geom.set_charge for an xyz structure')
else:
self.geom.__dict__.update(charge=self.geom.get_charge())

def _set_ions(self, ion_path=None, ion_list=None):
cations, anions, complex = _parse_ions(
ion_path=ion_path, ion_list=ion_list)
Expand Down Expand Up @@ -1032,11 +1011,11 @@ def _check_valid(self):
self.adducts['complex'] = self._filter_supported_by_xtb(
self.adducts['complex'])

if self.geom.load['filetype'] != '.xyz':
self.adducts['anions'] = _filter_by_substructure_match(
self.geom.mol, self.adducts['anions'])
self.adducts['complex'] = _filter_by_substructure_match(
self.geom.mol, self.adducts['complex'])

self.adducts['anions'] = _filter_by_substructure_match(
self.geom.mol, self.adducts['anions'])
self.adducts['complex'] = _filter_by_substructure_match(
self.geom.mol, self.adducts['complex'])

def configure(self, ion_path=None, ion_list=None):
self._set_ions(ion_path=ion_path, ion_list=ion_list)
Expand All @@ -1054,14 +1033,15 @@ def _parse_ion_charge(self, ion):
charge = int(charge[0])
return charge

# TODO: update this
def _update_geometry_charge(self, geom, adduct, ion_charge, mode):
'''
'''

if mode == 'negative':
charge = geom.__dict__.get('charge') - ion_charge
charge = geom.get_charge() - ion_charge
elif mode == 'positive':
charge = geom.__dict__.get('charge') + ion_charge
charge = geom.get_charge() + ion_charge
adduct.__dict__.update(charge=charge)

def _positive_mode(self, geom, forcefield, ewin, cation, optlevel, dryrun, processes, solvation, ignore_topology):
Expand All @@ -1070,7 +1050,7 @@ def _positive_mode(self, geom, forcefield, ewin, cation, optlevel, dryrun, proce
'''

output = md(geom, program='xtb', task='protonate', forcefield=forcefield,
ewin=ewin, ion=cation, optlevel=optlevel, dryrun=dryrun, charge=geom.charge, processes=processes, solvation=solvation, ignore_topology=ignore_topology)
ewin=ewin, ion=cation, optlevel=optlevel, dryrun=dryrun, processes=processes, solvation=solvation, ignore_topology=ignore_topology)
ion_charge = self._parse_ion_charge(cation)
for adduct in output.geom:
self._update_geometry_charge(geom, adduct, ion_charge, 'positive')
Expand All @@ -1082,7 +1062,7 @@ def _negative_mode(self, geom, forcefield, ewin, anion, optlevel, dryrun, proces
'''

output = md(geom, program='xtb', task='deprotonate', forcefield=forcefield,
ewin=ewin, ion=anion, optlevel=optlevel, dryrun=dryrun, charge=geom.charge, processes=processes, solvation=solvation, ignore_topology=ignore_topology)
ewin=ewin, ion=anion, optlevel=optlevel, dryrun=dryrun, processes=processes, solvation=solvation, ignore_topology=ignore_topology)
ion_charge = self._parse_ion_charge(anion)
for adduct in output.geom:
self._update_geometry_charge(geom, adduct, ion_charge, 'negative')
Expand Down Expand Up @@ -1181,9 +1161,6 @@ def run(self, geom, ion_path=None, ion_list=None, **kwargs):

self.set_geometry(geom)

# Infers charge for non xyz files, infers default neutral for xyz files
self.set_charge()

# Load specified ions by type
# Validity check if negative ionization can be done
# Validity check if CREST supports the ions specified
Expand Down
4 changes: 2 additions & 2 deletions isicle/conformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from statsmodels.stats.weightstats import DescrStatsW

from isicle import io
from isicle.geometry import Geometry, XYZGeometry
from isicle.geometry import Geometry
from isicle.utils import TypedList, safelist


Expand Down Expand Up @@ -382,7 +382,7 @@ def __init__(self, *args):
'''

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

def _check_attributes(self, attr):
'''
Expand Down
Loading

0 comments on commit 8b0757f

Please sign in to comment.