Skip to content

Ignoring valences read from sdf file #7127

Closed Answered by greglandrum
zarkoivkovicc asked this question in Q&A
Discussion options

You must be logged in to vote

@zarkoivkovicc The mol file parser interprets the valence flag and sets a couple of values on the atoms. You can manually change those and then run a normal sanitization and it should clear things up.
This function seems to work for at least simple cases:

def parse_mol_and_ignore_valence_tags(mb):
    mol = Chem.MolFromMolBlock(mb,sanitize=False,removeHs=False)
    for atom in mol.GetAtoms():
        atom.SetNoImplicit(False)
        atom.SetNumExplicitHs(0)
    Chem.SanitizeMol(mol)
    Chem.AssignStereochemistry(mol,cleanIt=True)
    return mol

Here's a simple demonstration to show it working:

In [24]: mb2 = '''
    ...:   Mrv2211 02022415472D          
    ...: 
    ...:   2  1  0  0 …

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by zarkoivkovicc
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants