Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDB Import issue : MolFromPDBFile() vs MolFromPDBBlock() #7362

Open
urekam712 opened this issue Apr 15, 2024 · 4 comments
Open

PDB Import issue : MolFromPDBFile() vs MolFromPDBBlock() #7362

urekam712 opened this issue Apr 15, 2024 · 4 comments
Labels

Comments

@urekam712
Copy link

urekam712 commented Apr 15, 2024

Kindly refer the file attached
The data from the file is used for both MolFromPDBFile() and MolFromPDBBlock()

#PDB FILE
from rdkit import Chem
from rdkit.Chem import AllChem, Draw, rdDepictor
from rdkit.Chem.Draw import rdMolDraw2D
from rdkit.Chem.Draw import rdMolDraw2D, rdDepictor
from rdkit.Chem.Draw import IPythonConsole
from IPython.display import SVG
k = Chem.MolFromPDBFile("DNA.pdb")

print(k)
d2d = Draw.MolDraw2DSVG(1000, 1000, -1, -1, True)
d2d.DrawMolecule(k)
d2d.FinishDrawing()
txt = d2d.GetDrawingText()
SVG(txt)

OUTPUT:
image

from rdkit import Chem
from rdkit.Chem import AllChem, Draw, rdDepictor
from rdkit.Chem.Draw import rdMolDraw2D
from rdkit.Chem.Draw import rdMolDraw2D, rdDepictor
from rdkit.Chem.Draw import IPythonConsole
from IPython.display import SVG
from rdkit import rdBase
from rdkit.Chem import Draw
print(rdBase.rdkitVersion)


pdb = "---pl add pdb string copied from the file attached below ---" 
m = Chem.MolFromPDBBlock(pdb)

print(m)
d2d = Draw.MolDraw2DSVG(250, 200, -1, -1, True)
d2d.DrawMolecule(m)
d2d.FinishDrawing()
txt = d2d.GetDrawingText()
SVG(txt)

output:
image

DNA.pdb.txt

@urekam712 urekam712 added the bug label Apr 15, 2024
@joseerlang
Copy link

Hi there,
I'm pretty new to the project, I'm still starting to understand it, but I think you need to use the function
Chem.MolToPDBBlock function before calling MolFromPDBBlock . You have an example in the following test

m = Chem.MolFromPDBBlock(Chem.MolToPDBBlock(m))

@urekam712 urekam712 reopened this Apr 23, 2024
@urekam712
Copy link
Author

urekam712 commented Apr 23, 2024

Hi there, I'm pretty new to the project, I'm still starting to understand it, but I think you need to use the function Chem.MolToPDBBlock function before calling MolFromPDBBlock . You have an example in the following test

m = Chem.MolFromPDBBlock(Chem.MolToPDBBlock(m))

refer this file pdbparser.cpp : https://github.com/rdkit/rdkit/blob/a087cfd894497e98936245605dd87ca7f0f3de2a/Code/GraphMol/FileParsers/PDBParser.cpp

where MolFromPDBFile calls ---> MolFromPDBDataStream( file data getting parsed) ---> MolFromPDBBlock

this is obvious that MolFromPDBFile depends on MolFromPDBBlock

then why this difference between importing MolFromPDBFile vs MolFromPDBBlock

@joseerlang

@

@joseerlang
Copy link

Hi @urekam712 ,

I think the problem you have in your code has to do with the way you define the pdb variable, because you are putting a string without the carriage returns and that is influencing the calling of the MolFromPDBBlock method.

I leave you an example that works in my installation so that you can try it in yours.

fileN = os.path.join(RDConfig.RDBaseDir, 'Code', 'GraphMol', 'FileParsers', 'test_data',
'1CRN.pdb')
with open(fileN, 'r') as f:
pdb = f.read()

m = Chem.MolFromPDBBlock(pdb)

print(m)
d2d = Draw.MolDraw2DSVG(250, 200, -1, -1, True)
d2d.DrawMolecule(m)
d2d.FinishDrawing()
txt = d2d.GetDrawingText()
SVG(txt)

@joseerlang
Copy link

@urekam712 could this ticket be closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants