Pymol-Scripts / Pymol-script-repo

Collected scripts for Pymol
http://www.pymolwiki.org/index.php/Git_intro
449 stars 256 forks source link

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

Open WeibinRen opened 3 months ago

WeibinRen commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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

pslacerda commented 3 months ago

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 commented 3 months ago

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