Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorporate charge handling #36

Merged
merged 1 commit into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading