schrodinger.application.matsci.smartsutils module

Utilities for working with SMARTS patterns

Copyright Schrodinger, LLC. All rights reserved.

class schrodinger.application.matsci.smartsutils.SMARTSGroupData(number, name, pattern, indexes)

Bases: tuple

__contains__

Return key in self.

__init__

Initialize self. See help(type(self)) for accurate signature.

__len__

Return len(self).

count()

Return number of occurrences of value.

index()

Return first index of value.

Raises ValueError if the value is not present.

indexes

Alias for field number 3

name

Alias for field number 1

number

Alias for field number 0

pattern

Alias for field number 2

schrodinger.application.matsci.smartsutils.validate_name(name)

Make sure name has the correct set of characters

Parameters:name (str) – The string to check
Return type:bool
Returns:True if name has no invalid characters, False if any characters are invalid
exception schrodinger.application.matsci.smartsutils.SMARTSGroupError

Bases: Exception

Class for exceptions related to SMARTS group finding

__init__

Initialize self. See help(type(self)) for accurate signature.

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

schrodinger.application.matsci.smartsutils.delete_group_properties(struct)

Delete all SMARTS group properties (structure and atom) from the structure

Parameters:struct (schrodinger.structure.Structure) – The structure to delete properties from
schrodinger.application.matsci.smartsutils.find_group_data(struct)

Find an SMARTS group data on the structure

Parameters:struct (schrodinger.structure.Structure) – The structure to find groups on
Return type:dict
Returns:A dictionary. Keys are smarts group numbers, values are SMARTSGroupData named tuples for the SMARTS group with that number
Raises:SMARTSGroupError – If something in the data is not consistent
schrodinger.application.matsci.smartsutils.get_rdkit_atoms(smarts)

Return a collection of rdkit atoms for the given SMARTS. The return value has the length of a potential match group, for example for ‘cc’ this length is 2, for ‘[$([NH]([CH2])[CH2])]C’ it is 2, for [n-0X2].[n-0X2] it is 2, etc., even though there might be any number of matches if the pattern was matched.

Parameters:smarts (str) – the SMARTS pattern
Raises:RuntimeError – if rdkit has a problem with the SMARTS
Return type:rdkit.Chem.rdchem._ROAtomSeq
Returns:the rdkit atoms
schrodinger.application.matsci.smartsutils.is_smarts_bonding_pair(smarts)

Return True if the given SMARTS would match a bonding pair, False otherwise.

Parameters:smarts (str) – the SMARTS pattern
Return type:bool
Returns:True if the SMARTS would match a bonding pair, False otherwise
class schrodinger.application.matsci.smartsutils.SMARTSGroup(name, pattern, logger=None)

Bases: object

Handles matching and record-keeping for a SMARTS patter

__init__(name, pattern, logger=None)

Create a SMARTSGroup object

Parameters:
  • name (str) – The name of this SMARTS group
  • pattern (str) – The SMARTS pattern for this group
Raises:
  • ValueError – If name has invalid characters
  • ValueError – If the SMARTS is invalid
nextNumber(numbers_used)

Get the next unused group number

Parameters:numbers_used (set) – Each member is a number that has already been used for a group and is unavailable. The number returned by this function is added to the numbers_used set.
Return type:int
Returns:The lowest available number. This number will have been added to the numbers_used set.
orderedMatches(struct, backbone_atoms)

Evaluate the smarts pattern matches, where matches are ordered to follow network sequence. Consider backbone atoms matches first in the sequence and the side chian matches are then ordered according to atom index.

Parameters:
  • struct (schrodinger.structure.Structure) – The structure to delete properties from
  • backbone_atoms (dict) – dictionary with key as molecule number and backbone atoms index ordered in a list
Return list(list):
 

List of list containing the smart pattern matches

match(struct, numbers_used, backbone_atoms)

Find all the SMARTS groups matching the SMARTS pattern and mark them with the appropriate properties

Parameters:
  • struct (schrodinger.structure.Structure) – The structure to delete properties from
  • numbers_used (set) – A set of all the group numbers that have been used and are unavailable
  • backbone_atoms (dict) – dictionary with key as molecule number and backbone atoms index ordered in a list