cgsmiles.pysmiles_utils module

cgsmiles.pysmiles_utils.annotate_ez_isomers_cgsmiles(molecule)[source]

Small wrapper dealing with ez_isomer annotation.

Parameters:

molecule (networkx.Graph) – The molecule of interest, which must of ez_isomer_pairs and ez_isomer_class set as node attributes

cgsmiles.pysmiles_utils.compute_mass(input_molecule)[source]

Compute the mass of a molecule from the PTE.

Parameters:

molecule (networkx.Graph) – molecule which must have element specified per node

Returns:

the atomic mass

Return type:

float

cgsmiles.pysmiles_utils.read_fragment_smiles(smiles_str, fragname, bonding_descrpt={}, ez_isomers={}, attributes={})[source]

Read a smiles_str corresponding to a CGsmiles fragment and annotate bonding descriptors, isomers, as well as any other attributes.

This function also sets default attributes as follows:

  • fragname to fragname

  • fragid to 0

  • w to 1

Parameters:
  • smiles_str (str) – string in OpenSMILES format

  • fragname (str) – the name of the fragment

  • ez_isomers (dict)

  • attributes (dict)

Returns:

the graph of the molecular fragment

Return type:

networkx.Graph

cgsmiles.pysmiles_utils.rebuild_h_atoms(mol_graph, keep_bonding=False, copy_attrs=['fragid', 'fragname', 'weight'])[source]

Helper function which add hydrogen atoms to the molecule graph.

First the hcount attribute produced by pysmiles is updated, because fragments have no bonds at time of reading so pysmiles does not know the connectivity. Hence the hcount is redone based on the actual connectivity of the final molecule.

This function also makes sure to tag single hydrogen fragments, in order to not merge them with adjecent fragments. Otherwise, explicit single hydrogen residues would not be possible.

The molecule graph is updated in place with the hydrogen atoms that are missing.

Using the keep_bonding argument the hydrogen count is reduced by the number of bonding descriptors. In this way hydrogen atoms can also be added to fragments only.

The copy_attrs argument defines a list of attributes to copy to the newly added hydrogen atoms. In case the hydrogen atoms are their own fragments attributes are not copied. If an attribute is already assigned, because the hydrogen atom was explicit that attribute is not replaced.

Parameters:
  • mol_graph (networkx.Graph) – graph describing the full molecule without hydrogen atoms

  • copy_attrs (list[collections.abc.Hashable]) – a list of attributes to copy from the parent node to the hydrogen atom

  • keep_bonding (bool) – adjust hcount for number of bonding descriptors