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

Mol2 files bonds #54

Open
btyukodi opened this issue Jul 6, 2018 · 8 comments
Open

Mol2 files bonds #54

btyukodi opened this issue Jul 6, 2018 · 8 comments

Comments

@btyukodi
Copy link

btyukodi commented Jul 6, 2018

PandasMol2().read_mol2() reads and parses a mol2 file, however, in the dataframe, only the @ATOM section is present. Is there any way to access the bonds?

Thanks
Botond

@rasbt
Copy link
Member

rasbt commented Jul 6, 2018

Hi there,

in the current version of biopandas, the Mol2 BOND section is not parsed, yet. You would need to parse it from the raw text data that is attached to a PandasMol2 object pmol via pmol.mol2_text.

I think adding some parsing functionality for the BOND section would be a good thing to do!


Since the analysis of bonds is not necessarily done in each virtual screening analysis/application, I would make parsing the bonds section not the default (but optional) for computational efficiency reasons.

A general "design" question now is whether a BOND DataFrame should be stored/accessed via

a) pmol.df_bonds (where pmol.df is currently storing the atom section)

or

b) pmol.df['bonds'] (where pmol.df would then have to be renamed to pmol.df['atom'], which would make it more consistent with PandasPdb())

pmol.parse_bonds() # method to parse the bonds section
pmol.df_bonds # dataframe containing the bonds section

Feedback and comments (and PRs!) are welcome!

@btyukodi
Copy link
Author

btyukodi commented Jul 6, 2018

Hi, thanks for your answer. Just wrote a quick, dirty and probably non-optimal parser. It could serve as a temporary solution:

def bond_parser(filename):
    f = open(filename,'r')
    f_text = f.read()
    f.close()
    bond_start = f_text.find('@<TRIPOS>BOND')
    bond_end = f_text[bond_start:].replace('@<TRIPOS>BOND','').find('@')
    df_bonds = pd.DataFrame(np.array(f_text[bond_start:bond_end].replace('@<TRIPOS>BOND\n','').replace('\n',' ').split(' ')).reshape((-1,4)),
            columns=['bond_id', 'atom1', 'atom2', 'bond_type'])
    df_bonds.set_index(['bond_id'], inplace=True)
    return df_bonds

@wlgfour
Copy link

wlgfour commented Sep 10, 2020

Here is a shorter version of of what @btyukodi wrote that uses regex:

dwef bond_parset(filename):
    with open(filename, 'r') as f:
        f_text = f.read()
    bonds =  np.array(re.sub(r'\s+', ' ', re.search(r'@<TRIPOS>BOND([a-z0-9\s]*)@', f_text).group(1)).split()).reshape((-1, 4))
    df_bonds = pd.DataFrame(bonds, columns=['bond_id', 'atom1', 'atom2', 'bond_type'])
    df_bonds.set_index(['bond_id'], inplace=True)
    return df_bonds

@rasbt
Copy link
Member

rasbt commented Sep 10, 2020

Thanks a lot. I totally forgot about this / got to busy to work on this. Thanks for sharing though, I hopefully will get to it one day (or maybe someone else :))

@mercicle
Copy link

mercicle commented Dec 3, 2020

Hey there all, was this ever implemented?

@rasbt
Copy link
Member

rasbt commented Dec 3, 2020

No, sorry, never really found the time to do that :(

@Kroppeb
Copy link

Kroppeb commented May 14, 2022

Seems like this is still an open issue?

@rasbt
Copy link
Member

rasbt commented May 14, 2022

yeah, this is still an open issue

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

No branches or pull requests

5 participants