Skip to content

Commit

Permalink
Edited all comments and docstrings which feature rdtypes classes (e.g…
Browse files Browse the repository at this point in the history
…. RDMol, RDBond, RDAtom, or RWMol) in preparation for mass-rename
  • Loading branch information
timbernat committed May 15, 2024
1 parent 10bc8a2 commit bc87fea
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 22 deletions.
6 changes: 3 additions & 3 deletions polymerist/monomers/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


# CUSTOM EXCEPTIONS
class InvalidRDMol(Exception):
class InvalidRDKitMol(Exception):
# raised during validation and error checking to catch invalid inputted/generated monomers
def __init__(self, message, smarts=""):
self.message = message
Expand All @@ -27,10 +27,10 @@ def __str__(self):
else:
return f"rdmol with smarts \"{self.smarts}\" found to be invalid: {self.message}"

class InvalidMonomer(InvalidRDMol):
class InvalidMonomer(InvalidRDKitMol):
pass

class InvalidCap(InvalidRDMol):
class InvalidCap(InvalidRDKitMol):
pass

# CONVERTERS
Expand Down
2 changes: 1 addition & 1 deletion polymerist/monomers/repr.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def unique(self, cap_group : Union[str, RDMol]=Chem.MolFromSmarts('[H]-[*]')) ->
# monomer = Chem.MolFromSmarts(SMARTS)
# clear_atom_map_nums(monomer, in_place=True)
# hydrogenate_monomer_ports(monomer, in_place=True)
# unique_mono.add(Chem.MolToSmiles(monomer)) # TODO : eventually make this SMART-based (or even better RDMol-based); can't for now since hydrogenated fragments don't equate
# unique_mono.add(Chem.MolToSmiles(monomer)) # TODO : eventually make this SMARTS-based (or even better RDKit Mol-based); can't for now since hydrogenated fragments don't equate

# return unique_mono

Expand Down
2 changes: 1 addition & 1 deletion polymerist/monomers/specification.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def compliant_atom_query_from_info(atomic_num : int, degree : int, atom_map_num
return atom_query

def compliant_atom_query_from_rdatom(rdatom : RDAtom, as_atom : bool=False) -> Union[str, QueryAtom]:
'''Construct a monomer-spec compliant atom SMARTS string from an RDKit RDAtom'''
'''Construct a monomer-spec compliant atom SMARTS string from an RDKit Atom'''
return compliant_atom_query_from_info(
atomic_num = rdatom.GetAtomicNum(),
degree = rdatom.GetDegree(), # counts number of active bonds
Expand Down
2 changes: 1 addition & 1 deletion polymerist/openfftools/solvation/physprops.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


def molecular_weight(rdmol : RDMol, exact_isotopes : bool=False) -> Quantity:
'''Compute the molecular weight of an RDMol'''
'''Compute the molecular weight of an RDKit Mol'''
MW = Descriptors.ExactMolWt(rdmol) if exact_isotopes else Descriptors.MolWt(rdmol)
return MW * (gram / mole) # attach units

Expand Down
2 changes: 1 addition & 1 deletion polymerist/rdutils/bonding/identification.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def enumerate_bondable_port_pairs_internal(ports : Iterable[Port]) -> Generator[
# return get_bondable_ports(rdmol, rdmol) # currently, this overcounts by exactly double, as a pair (p1, p2) and its copair (p2, p1) are considered distinct

def get_bondable_port_pairs(rdmol : RDMol, atom_id_1 : Optional[int]=None, atom_id_2 : Optional[int]=None, flavor_pair : tuple[Optional[int], Optional[int]]=(None, None)) -> Generator[tuple[Port, Port], None, None]:
'''Get every pair of ports within an RDMol which could be bonded and match a specified flavor pair (could be partially or fully None for less specificity)
'''Get every pair of ports within an RDKit Mol which could be bonded and match a specified flavor pair (could be partially or fully None for less specificity)
Can optionally localize search to only have port bridegehead coinciding with atoms at particular indices
Pairs are returned n descending order of linker atom index to simplify atom removal if modifying later'''
# possible_port_pairs = enumerate_bondable_port_pairs_internal( # unpack values after iterating; TODO : make this internal to avoid double counting
Expand Down
2 changes: 1 addition & 1 deletion polymerist/rdutils/bonding/portlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def matches_flavor(self, target_flavor : Optional[int]) -> bool:

# PORT ENUMERATION
def get_port_ids(rdmol : RDMol) -> Generator[tuple[int, int], None, None]:
'''Get the linker and bridgehead indices of all ports found in an RDMol'''
'''Get the linker and bridgehead indices of all ports found in an RDKit Mol'''
for (linker_id, bh_id) in rdmol.GetSubstructMatches(PORT_QUERY):
yield linker_id, bh_id # unpacked purely for self-documentation

Expand Down
2 changes: 1 addition & 1 deletion polymerist/rdutils/bonding/substitution.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def splice_atoms(rwmol : RWMol, atom_id_1 : Optional[int]=None, atom_id_2 : Opti
increase_bond_order(rwmol, atom_id_1, atom_id_2, flavor_pair=flavor_pair, in_place=True)

def saturate_ports(rdmol : RDMol, cap : RDMol=Chem.MolFromSmarts('[#0]-[#1]'), flavor_to_saturate : int=0) -> None:
'''Takes an RDMol and another "cap" molecule (by default just hydrogen) and caps all valid ports (with the specified flavor) on the target Mol with the cap group'''
'''Takes an RDKit Mol and another "cap" molecule (by default just hydrogen) and caps all valid ports (with the specified flavor) on the target Mol with the cap group'''
flavor_pair : tuple[int, int] = (flavor_to_saturate, get_single_port(cap).flavor) # will raise exception if cap has anything other than 1 port

rwmol = combined_rdmol(rdmol, cap, editable=True) # create initial combination to test if bonding is possible
Expand Down
2 changes: 1 addition & 1 deletion polymerist/rdutils/labeling/bondwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

# BOND ID QUERYING
def are_bonded_atoms(rdmol : RDMol, atom_id_1 : int, atom_id_2 : int) -> bool:
'''Check if pair of atoms in an RDMol have a bond between them'''
'''Check if pair of atoms in an RDKit Mol have a bond between them'''
return (rdmol.GetBondBetweenAtoms(atom_id_1, atom_id_2) is not None)

def get_bonded_pairs(rdmol : RDMol, *atom_ids : Iterable[int]) -> dict[int, tuple[int, int]]:
Expand Down
14 changes: 7 additions & 7 deletions polymerist/rdutils/labeling/molwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@

# READING FUNCTIONS
def get_isotopes(rdmol : RDMol, unique : bool=True) -> Union[set[int], list[int]]:
'''Return all isotope IDs present in an RDMol. Can optionally return only the unique IDs'''
'''Return all isotope IDs present in an RDKit Mol. Can optionally return only the unique IDs'''
isotope_ids = [atom.GetIsotope() for atom in rdmol.GetAtoms()]

if unique:
return set(isotope_ids)
return isotope_ids

def ordered_map_nums(rdmol : RDMol) -> list[int]:
'''Get assigned atom map numbers, in the same order as the internal RDMol atom IDs'''
'''Get assigned atom map numbers, in the same order as the internal RDKit Mol atom IDs'''
return [atom.GetAtomMapNum() for atom in rdmol.GetAtoms()]

def map_nums_by_atom_ids(rdmol : RDMol, *query_atom_ids : list[int]) -> Generator[Optional[int], None, None]: # TODO : generalize this to handle case where multiple atoms have the same map num
'''Get assigned atom map numbers for a collection of atom ids, in the same order as the internal RDMol atom IDs'''
'''Get assigned atom map numbers for a collection of atom ids, in the same order as the internal RDKit Mol atom IDs'''
for atom_id in query_atom_ids:
yield(rdmol.GetAtomWithIdx(atom_id).GetAtomMapNum())

Expand All @@ -36,15 +36,15 @@ def atom_ids_by_map_nums(rdmol : RDMol, *query_map_nums : list[int]) -> Generato

# CHECKING FUNCTIONS
def has_fully_mapped_atoms(rdmol : RDMol) -> bool:
'''Check whether an RDMol has a map number explicitly assigned to each member RDAtom'''
'''Check whether an RDKit Mol has a map number explicitly assigned to each member Atom'''
for atom in rdmol.GetAtoms():
if atom.GetAtomMapNum() == 0:
return False
else:
return True

def has_uniquely_mapped_atoms(rdmol : RDMol) -> bool:
'''Check whether an RDMol has distinct atom map numbers for each member RDAtom'''
'''Check whether an RDKit Mol has distinct atom map numbers for each member Atom'''
map_nums = ordered_map_nums(rdmol)
return (len(map_nums) == len(set(map_nums))) # NOTE : not using rdmol.GetNumAtoms() as reference to avoid ambiguity with SMILES without explicit Hs

Expand Down Expand Up @@ -93,12 +93,12 @@ def assign_contiguous_atom_map_nums(*rdmols : Iterable[RDMol], start_from : int=
# CLEARING FUNCTIONS
@optional_in_place
def clear_atom_map_nums(rdmol : RDMol) -> None:
'''Removes atom map numbers from all atoms in an RDMol'''
'''Removes atom map numbers from all atoms in an RDKit Mol'''
for atom in rdmol.GetAtoms():
atom.SetAtomMapNum(0)

@optional_in_place
def clear_atom_isotopes(rdmol : RDMol) -> None:
'''Removes isotope numbers from all atoms in an RDMol'''
'''Removes isotope numbers from all atoms in an RDKit Mol'''
for atom in rdmol.GetAtoms():
atom.SetIsotope(0)
2 changes: 1 addition & 1 deletion polymerist/rdutils/rdconvert.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'''For conversion of RDMols back and forth between different format encodings - often imbues a desired side effect (such as 2D-projection)'''
'''For conversion of RDKit Mols back and forth between different format encodings - often imbues a desired side effect (such as 2D-projection)'''

from abc import ABC, abstractmethod, abstractproperty
from rdkit import Chem
Expand Down
4 changes: 2 additions & 2 deletions polymerist/rdutils/rdkdraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ def disable_substruct_highlights() -> None:
IPythonConsole.highlightSubstructs = False

def set_rdkdraw_size(dim : int=300, aspect : float=3/2):
'''Change image size and shape of RDMol images'''
'''Change image size and shape of RDKit Mol images'''
IPythonConsole.molSize = (int(aspect*dim), dim) # Change IPython image display size


# SINGLE-MOLECULE DISPLAY OPTIONS
def clear_highlights(rdmol : RDMol) -> None:
'''Removes the highlighted atoms flags from an RDMol if present'''
'''Removes the highlighted atoms flags from an RDKit Mol if present'''
if hasattr(rdmol, '__sssAtoms'):
del rdmol.__sssAtoms

Expand Down
4 changes: 2 additions & 2 deletions polymerist/rdutils/reactions/reactors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'''Classes for implementing reactions with respect to some set of reactant RDMols'''
'''Classes for implementing reactions with respect to some set of reactant RDKit Mols'''

from typing import ClassVar, Generator, Iterable, Optional, Type
from dataclasses import dataclass, field
Expand All @@ -21,7 +21,7 @@
# REACTOR BASE CLASS
@dataclass
class Reactor:
'''Class for executing a reaction template on collections of RDMol "reactants"'''
'''Class for executing a reaction template on collections of RDKit Mol "reactants"'''
rxn_schema : AnnotatedReaction
_ridx_prop_name : ClassVar[str] = field(init=False, default='reactant_idx') # name of the property to assign reactant indices to; set for entire class

Expand Down

0 comments on commit bc87fea

Please sign in to comment.