ball icon indicating copy to clipboard operation
ball copied to clipboard

Cannot find MODE_OUT in Python

Open smoe opened this issue 9 years ago • 2 comments

Hello,

I have difficulties in writing a protein/system to a PDBFile. The problem may have its root for the specification of the OpenMode.

In [1]: from BALL import *
In [2]: testme = PDBFile("bla.pdb",File.MODE_OUT)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
 in ()
----> 1 testme = PDBFile("bla.pdb",File.MODE_OUT)
AttributeError: type object 'File' has no attribute 'MODE_OUT'

and I do not find the MODE_OUT elsewhere, either. A C++ implementation worked.

I then used the numerical value 1 directly as seen in https://github.com/BALL-Project/ball/blob/8997b8153d342656a93f70230e72861b83a5540e/include/BALL/SYSTEM/file.h#L168

which then works

testme = PDBFile("bla.pdb",1)

and an empty file is indeed created but I still fail to write to it

system=System()
testme.write(system)
---------------------------------------------------------------------------
SystemError                               Traceback (most recent call last)
SystemError: 'finally' pops bad exception

The same happens with a protein, so I understand this is not depending on the actual content.

smoe avatar May 28 '15 08:05 smoe

Hello again, the problem can still be observed, i.e. the example of https://github.com/BALL-Project/ball/wiki/WriteAPDBFile is definitely not working. Please kindly give some directions.

smoe avatar Jun 26 '15 13:06 smoe

Well, what can I say, it truly nags at you when you cannot get the results of the compute printed. The issue is likely to be associated with the declaration of the class File in file.sip no longer seeing the definition of the constant MODE_OUT, i.e. it is commented out (see https://github.com/BALL-Project/ball/blob/master/source/PYTHON/EXTENSIONS/BALL/file.sip#L25), which was apparently done for some c++-11 compatibility issues (https://github.com/BALL-Project/ball/commit/6700400576521250cbe4f8d201391168eb80e0df).

After some browsing of the source code I came up with

In [11]: collagenPDBfileOut=PDBFile("bla.pdb",OpenMode(16))
In [12]: collagenPDBfileOut.write(p)

which worked, benefiting from the insight gathered from

In [29]: for i in range(0,100):
    print i,OpenMode(i)
   ....:
0 std::ios::in
1 std::ios::app
2 std::ios::ate
3 std::ios::in
4 std::ios::binary
...
8 std::ios::in
...
15 std::ios::in
16 std::ios::out
17 std::ios::in
...
31 std::ios::in
32 std::ios::trunc
33 std::ios::in
...

I happily help with getting bits and pieces somewhat more user-friendly. Just direct me a bit on how you would want it, please. Shall OpenMode possibly accept strings as an initialiser? I expect whatever your answer is that this will affect quite a few routines.

smoe avatar Jun 26 '15 16:06 smoe