MonZop / BioBlender

AddOn for Blender to do molecular work
BSD 2-Clause "Simplified" License
113 stars 20 forks source link

BB2 doesn't import all conformations. #15

Closed zeffii closed 9 years ago

zeffii commented 9 years ago

@MonZop found:

The file contains 4 MODELS (conformations), but I noticed that BB2 only imports 3 of them. I also tried to import other proteins that have many conformations, but BB2 imports all models except the last one.

This seems like an off by one error or other indexing mistake.

zeffii commented 9 years ago

just to be clear, this means all files with N conformations, only import N - 1 of those? It's not just the 06_1L2Y_4LGE.pdb

MonZop commented 9 years ago

exactly: all tested files import all conformations -1

MonZop commented 9 years ago

The last version 273_compatible, downloaded 10 minutes ago, does import all conformations, in some cases (I still have not clear which are OK and which are not)

zeffii commented 9 years ago

I think it may be something simple, but haven't tracked it down yet.

zeffii commented 9 years ago

problem case

The 06_1L2Y_4LGE.pdb test pdb, has 4 conformations (named 1,3,4,5) but only keyframes 1,3,4 are created

time for some process of elimination and some assumptions.

MonZop commented 9 years ago

I think that when BB 'make preview' of a file, it makes a copy that is stored in some temporarty file. This is because sometimes pdb files are fetched directly from the databank, and it is useful to have a local copy. The copy might also be used for the subsequent steps of adding charge value to each atom (done by PDB2PQR)

zeffii commented 9 years ago

Right! The importPreview function (when successful) will either obtain the pdb from [pdb.org]() or read the local file . The function does not edit the file, merely gather information. The error isn't there (at least, i've read it carefully, and it appears OK)

zeffii commented 9 years ago

it's narrowed down to the core_parsePDB function. It's not a big function, so I expect progress today.

zeffii commented 9 years ago

cool. I'm pretty sure it's this, the last line flattens the dict..

# when the end of a tmpPDBmodelDictionary is reached, add the tmpPDBmodelDictionary dictionary to the list
if tag == "ENDMDL" or tag=="END" or tag == "MODEL" and (tmpPDBmodelID in tmpPDBmodelImportOrder):
    # We add a new MODEL entry to the global pdbIDmodelsDictionary[pdbID],
    # based on the current MODEL ID, and we assign the tmpPDBmodelDictionary to this entry.
    (pdbIDmodelsDictionary[pdbID])[tmpPDBmodelID] = tmpPDBmodelDictionary
    # So now pdbIDmodelsDictionary[pdbID] is a Dictionary: model-dict; the second dict is [atomName]-BBInfo
    tmpPDBmodelDictionary = {}

When there are more conformations to follow, the tmpPDBmodelDictionary gets repopulated, but if it's the last one, then the reference is overwritten with an empty dict one time too many.

MonZop commented 9 years ago

Great! I have no doubt that having found the problem you also have the solution! (always thankful)

zeffii commented 9 years ago

yeah, fixing is the easy part! finding, can be a slow process (but i should really have found this sooner)

zeffii commented 9 years ago

Will have to read slowly: http://www.biostat.jhsph.edu/~iruczins/teaching/260.655/links/pdbformat.pdf http://deposit.rcsb.org/adit/docs/pdb_atom_format.html

OK, fixing might be a little slower, it will need to take into consideration the various permutations that these pdb files can have. I'd like to be a bit more confident about knowing the permutations before committing to a fix.

zeffii commented 9 years ago

image

if the pdb is always formatted in a certain way (for multiple conformations), like:

MODEL   1
ATOM
ATOM
ATOM
...
TER
ENDMOL
MODEL    2
ATOM
ATOM
ATOM
...
TER
ENDMOL
END

it would be easy.. but as mentioned, i'm assuming there are deviations possible to the way programs write this sequences.

@MonZop can you show other permutations or is this the only valid way to encode multiple conformations in one file?

MonZop commented 9 years ago

To my knowledge all pdb files should be formatted as you show. The committee that run the repository ( Protein Data Bank), check that all submissions comply. there are discussions about new pdb formats, especially for huge molecular complexes (millions of atoms), but for now the known pdb format shiuld be safe

MonZop commented 9 years ago

For data obtained by molecular dynamics there is a different format, which includes a single pdb descrption and the trajectory for each atom. Readers for this format are available, but i would leave this issue for a next development of bioblender

zeffii commented 9 years ago

OK, then the current branch https://github.com/MonZop/BioBlender/tree/master_mff_experiments is reasonably the next pull request. Try it.

MonZop commented 9 years ago

Yes, tomorrow

MonZop commented 9 years ago

bb2addon oh oh, something's wrong..

MonZop commented 9 years ago

details Maybe this helps?

zeffii commented 9 years ago

Everything will be OK :)

The problem here luckily is not the addon, but how the addon is installed. In my opinion this is a general flaw in the add-on installation / storage mechanism of Blender itself. Hopefully I can explain.

zeffii commented 9 years ago

This has to do with how to test Branches.

zeffii commented 9 years ago

I've just pushed a change to BioBlender-master-mmf-experiments which allows you to name the folder whatever you want. But having multiple version of BioBlender in the addons directory is a headache I avoid by using the GitHub desktop application.

I've moved my answer to : https://github.com/MonZop/BioBlender/issues/9#issuecomment-74071711

MonZop commented 9 years ago

C:\blender_trunk\blender-2.73-8cd106f-win64\2.73\scripts\addons C:\Program Files\Blender Foundation\blender-2.73a-windows64\2.73\scripts\addons C:\Program Files\Blender Foundation\Blender\2.73\scripts\addons C:\Users\Monica\AppData\Roaming\Blender Foundation\Blender\2.73\scripts\addons

I have looked for BioBlender AddOn in all these places, but found it nowhere. All the zip BioBlender versions are in another folder, that does not contain Blender. I finally renamed the very latest (just downloaded) version to BioBlender2, and it still get the warining, but it does install BB2.

Now I can test it!

zeffii commented 9 years ago

if it imports all conformations from 01 and 06 pdb, then you know it's running the right versions. Hopefully the EP lines are also more accurate

MonZop commented 9 years ago

Import is OK, all confomrations (up to 38, just tested)

MonZop commented 9 years ago

EP lines also look good

MonZop commented 9 years ago

Will have to check line animation (re-calculation of lines during protein motion)

zeffii commented 9 years ago

in function core_parsePDB, the solution which is simplest and seems to behave well for the demo .pdb files is, instead of this

# when the end of a tmpPDBmodelDictionary is reached, add the tmpPDBmodelDictionary dictionary to the list
if tag == "ENDMDL" or tag=="END" or tag == "MODEL" and (tmpPDBmodelID in tmpPDBmodelImportOrder):
    # We add a new MODEL entry to the global pdbIDmodelsDictionary[pdbID],
    # based on the current MODEL ID, and we assign the tmpPDBmodelDictionary to this entry.
    (pdbIDmodelsDictionary[pdbID])[tmpPDBmodelID] = tmpPDBmodelDictionary
    # So now pdbIDmodelsDictionary[pdbID] is a Dictionary: model-dict; the second dict is [atomName]-BBInfo
    tmpPDBmodelDictionary = {}

it's this:

# when the end of a tmpPDBmodelDictionary is reached, add the tmpPDBmodelDictionary dictionary to the list
if tag == "ENDMDL" or tag=="END" or tag == "MODEL" and (tmpPDBmodelID in tmpPDBmodelImportOrder):
    # We add a new MODEL entry to the global pdbIDmodelsDictionary[pdbID],
    # based on the current MODEL ID, and we assign the tmpPDBmodelDictionary to this entry.
    if tmpPDBmodelDictionary:
        # don't push an empty tmpPDBmodelDictionary onto pdbIDmodelsDictionary.
        (pdbIDmodelsDictionary[pdbID])[tmpPDBmodelID] = tmpPDBmodelDictionary
    # So now pdbIDmodelsDictionary[pdbID] is a Dictionary: model-dict; the second dict is [atomName]-BBInfo
    tmpPDBmodelDictionary = {}
zeffii commented 9 years ago

this fixes multi-conformation pdb import and doesn't appear to have negative side effects with other kinds of pdb. Closing for now