Re: [Rdkit-discuss] Iterate through atoms in molecule including hydrogens in Python

2023-10-09 Thread Jeremy Monat
Thanks, Diogo and Fio. That solved that problem.

Jeremy

On Sun, Oct 8, 2023 at 1:23 AM Diogo Martins  wrote:

> Hi Jeremy,
>
> Chem.AddHs returns a new molecule, you could reassign the variable:
>
> mol = Chem.AddHs(mol)
>
> Best regards,
> Diogo
>
> On Sat, Oct 7, 2023 at 9:36 PM Jeremy Monat  wrote:
>
>> In Python, I'd like to iterate through all the atoms in a molecule,
>> including hydrogens, so I can assign an isotope to each atom. I haven't
>> been able to include hydrogens in the iterable of atoms:
>>
>> from rdkit import Chem
>>
>> mol = Chem.MolFromSmiles("CCO") # Example molecule: Ethanol (C2H5OH)
>>
>> # Add explicit hydrogens
>> Chem.AddHs(mol)
>>
>> for atom in mol.GetAtoms():
>> print(f"Atom Symbol: {atom.GetSymbol()}")
>> Output:
>> Atom Symbol: C
>> Atom Symbol: C
>> Atom Symbol: O
>>
>> Similarly, mol.GetAtomWithIdx() works up to an index of only 3, giving
>> C, C, and O atoms but no hydrogens.
>>
>> Thanks,
>> Jeremy
>>  -- ~ -- ~ --
>> Jeremy Monat, PhD
>> LinkedIn: http://www.linkedin.com/in/jemonat
>> Portfolio: https://bertiewooster.github.io
>> GitHub: https://github.com/bertiewooster
>> ___
>> Rdkit-discuss mailing list
>> Rdkit-discuss@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
>>
> ___
> Rdkit-discuss mailing list
> Rdkit-discuss@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
>
___
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss


[Rdkit-discuss] Iterate through atoms in molecule including hydrogens in Python

2023-10-07 Thread Jeremy Monat
In Python, I'd like to iterate through all the atoms in a molecule,
including hydrogens, so I can assign an isotope to each atom. I haven't
been able to include hydrogens in the iterable of atoms:

from rdkit import Chem

mol = Chem.MolFromSmiles("CCO") # Example molecule: Ethanol (C2H5OH)

# Add explicit hydrogens
Chem.AddHs(mol)

for atom in mol.GetAtoms():
print(f"Atom Symbol: {atom.GetSymbol()}")
Output:
Atom Symbol: C
Atom Symbol: C
Atom Symbol: O

Similarly, mol.GetAtomWithIdx() works up to an index of only 3, giving C,
C, and O atoms but no hydrogens.

Thanks,
Jeremy
 -- ~ -- ~ --
Jeremy Monat, PhD
LinkedIn: http://www.linkedin.com/in/jemonat
Portfolio: https://bertiewooster.github.io
GitHub: https://github.com/bertiewooster
___
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss


Re: [Rdkit-discuss] H atoms at ring junction

2023-06-07 Thread Jeremy Monat
Very nice! The picture in the thread above didn't come through for me. I
re-ran that code and got the following output, included as both an inline
PNG and an attached SVG so hopefully it shows up for folks in at least one:
[image: h_atoms_at_ring_jn.png]

On Mon, Jun 5, 2023 at 3:15 AM Jean-Marc Nuzillard <
jm.nuzill...@univ-reims.fr> wrote:

> Dear Paolo,
>
> many thanks, your solution worked like a charm!
>
> Best regards,
>
> Jean-Marc
>
>
> Le 01/06/2023 à 23:57, Paolo Tosco a écrit :
>
> Dear Jean-Marc,
>
> you may retain the original mol block wedging and avoid introducing H
> atoms as follows:
>
> from rdkit import Chem
> from rdkit.Chem.Draw import rdMolDraw2D
> from IPython.display import SVG
>
> mol = Chem.MolFromMolBlock("""trans-decalin
>  RDKit  2D
>
>  10 11  0  0  0  0  0  0  0  0999 V2000
> 1.50000.0. C   0  0  0  0  0  0  0  0  0  0 0  0
> 0.7500   -1.29900. C   0  0  0  0  0  0  0  0  0  0 0  0
>-0.7500   -1.29900. C   0  0  0  0  0  0  0  0  0  0 0  0
>-1.50000.0. C   0  0  0  0  0  0  0  0  0  0 0  0
>-3.0.0. C   0  0  0  0  0  0  0  0  0  0 0  0
>-3.75001.29900. C   0  0  0  0  0  0  0  0  0  0 0  0
>-3.2.59810. C   0  0  0  0  0  0  0  0  0  0 0  0
>-1.50002.59810. C   0  0  0  0  0  0  0  0  0  0 0  0
>-0.75001.29900. C   0  0  0  0  0  0  0  0  0  0 0  0
> 0.75001.29900. C   0  0  0  0  0  0  0  0  0  0 0  0
>   1  2  1  0
>   2  3  1  0
>   4  3  1  1
>   4  5  1  0
>   5  6  1  0
>   6  7  1  0
>   7  8  1  0
>   9  8  1  6
>   9 10  1  0
>  10  1  1  0
>   9  4  1  0
> M  END
> """)
>
> drawer = rdMolDraw2D.MolDraw2DSVG(300, 200)
> drawer.drawOptions().prepareMolsBeforeDrawing = False
> mol_draw = rdMolDraw2D.PrepareMolForDrawing(mol, addChiralHs=False, 
> wedgeBonds=False)
> Chem.ReapplyMolBlockWedging(mol_draw)
> drawer.DrawMolecule(mol_draw)
> drawer.FinishDrawing()
> SVG(drawer.GetDrawingText())
>
>
> Cheers,
> p.
>
> On Thursday, June 1, 2023, Jean-Marc Nuzillard 
> wrote:
>
>> Dear all,
>>
>> starting from this mol block:
>> trans-decalin
>>  RDKit  2D
>>
>>  10 11  0  0  0  0  0  0  0  0999 V2000
>> 1.50000.0. C   0  0  0  0  0  0  0  0  0  0  0  0
>> 0.7500   -1.29900. C   0  0  0  0  0  0  0  0  0  0  0  0
>>-0.7500   -1.29900. C   0  0  0  0  0  0  0  0  0  0  0  0
>>-1.50000.0. C   0  0  0  0  0  0  0  0  0  0  0  0
>>-3.0.0. C   0  0  0  0  0  0  0  0  0  0  0  0
>>-3.75001.29900. C   0  0  0  0  0  0  0  0  0  0  0  0
>>-3.2.59810. C   0  0  0  0  0  0  0  0  0  0  0  0
>>-1.50002.59810. C   0  0  0  0  0  0  0  0  0  0  0  0
>>-0.75001.29900. C   0  0  0  0  0  0  0  0  0  0  0  0
>> 0.75001.29900. C   0  0  0  0  0  0  0  0  0  0  0  0
>>   1  2  1  0
>>   2  3  1  0
>>   4  3  1  1
>>   4  5  1  0
>>   5  6  1  0
>>   6  7  1  0
>>   7  8  1  0
>>   9  8  1  6
>>   9 10  1  0
>>  10  1  1  0
>>   9  4  1  0
>> M  END
>>
>> I tried to experiment with the great post recently published
>> in the rdkit-blog about drawing options.
>> The Mol block hereabove has no explicit hydrogen
>> but the function DrawMolecule()
>> adds two hydrogen atoms at the ring junction :
>>
>> Even though this feature can be very helpful,
>> is it possible to let wedges along C-C bonds
>> carry out the geometry information without
>> introducing H atoms at the ring junction?
>>
>> Best,
>>
>> Jean-Marc Nuzillard
>>
>> --
>> Jean-Marc Nuzillard
>> Directeur de Recherches au CNRS
>>
>> Institut de Chimie Moléculaire de Reims
>> CNRS UMR 7312
>> Moulin de la Housse
>> CPCBAI, Bâtiment 18
>> BP 1039
>> 51687 REIMS Cedex 2
>> France
>>
>> ORCID : -0002-5120-2556
>> Tel : +33 (0)3 26 91 82 10
>> http://www.univ-reims.fr/icmr
>> https://nuzillard.github.io/PyLSD
>>
>>
>
> --
> Jean-Marc Nuzillard
> Directeur de Recherches au CNRS
>
> Institut de Chimie Moléculaire de Reims
> CNRS UMR 7312
> Moulin de la Housse
> CPCBAI, Bâtiment 18
> BP 1039
> 51687 REIMS Cedex 2
> France
>
> ORCID : -0002-5120-2556
> Tel : +33 (0)3 26 91 82 10
> http://www.univ-reims.fr/icmr
> https://nuzillard.github.io/PyLSD
>
> ___
> Rdkit-discuss mailing list
> Rdkit-discuss@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
>
___
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss