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

'string.split()' causes issue in 'Pymol-script-repo/modules/ADT/MolKit /pdbParser.py' #149

Open
WeibinRen opened this issue Aug 5, 2024 · 4 comments

Comments

@WeibinRen
Copy link

See line 1392 as example,
atom._coords = [ [ float(rec[5]), float(rec[6]), float(rec[7]) ] ]
the rec here comes from line 1308:
rec = split(rec)
Sometimes protein PDB file content looks like(protein 2p7a from PDBBind database):
ATOM 406 O ASP A 259 66.586 -29.223-100.911 1.00 14.83 O
If directly use string.split() here, the number -29.223-100.911 will not be split correctly.
It will raise error like:
ValueError: could not convert string to float: '-29.223-100.911'

@WeibinRen
Copy link
Author

I solved this by re-write split function:

def split(s):
    s_list = s.split()
    idx = 0
    while idx < len(s_list):
        item = s_list[idx]
        if '-' in item[1:]:
            index_minus = item.find('-', 1)
            s_list[idx] = item[:index_minus]
            s_list.insert(idx+1, item[index_minus:])
            idx = 0
        else:
            idx += 1
    return s_list

There should be some better way, I put the code here just hope this can help somebody in case they need this.

@WeibinRen
Copy link
Author

Also line 1309 seem not 100% correct to use ==10

@pslacerda
Copy link
Member

Hi, can you rewrite using a fixed string length like said at PDB ATOM record and submit as a pull request?

rec[31:39], rec[39:47]...

@pslacerda
Copy link
Member

I don't know how to test this plugin. If you rewrite like I said, i'll accept as is.

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

No branches or pull requests

2 participants