From: Thomas H. <tho...@sc...> - 2019-05-26 12:11:41
|
Hi Lorenzo, Looks like the cmd.bond() function is indeed very inefficient. I've found a "TO DO: optimize for performance" comment in the code - that speaks for itself. https://github.com/schrodinger/pymol-open-source/blob/master/layer2/ObjectMolecule.cpp#L4492 Parallelization is not the solution. You are probably right that a new API function is needed which allows you to directly add a bond by atom indices instead of atom selections. Cheers, Thomas > On May 25, 2019, at 5:11 PM, Lorenzo Gaifas <br...@gm...> wrote: > > Hi Blaine, > > Thanks for your help. > I don't think what you suggest is going to solve the problem. The loop itself is quite fast, and I don't need to perform anything else in the loop other than adding those bonds. > I already have a list of tuples [(atom1, atom2), (atom3, atom4)] and all I need to do is create a bond between each pair. The bottleneck is the bond function, not the loop itself. > > Also, I doubt simply the speed difference between C++ and Python could explain such a drastic difference (minutes against fractions of a second). There is clearly a difference in the way the `bond` command is implemented and the way bonds are generated at startup. > > What I think is needed, is either a way for pymol to perform those actions in parallel (unlikely) or a way to get my hands on the way bonds are generated at startup and use those functions or at least the same approach. > > Thank you, > Lorenzo > > Il giorno sab 25 mag 2019 alle ore 16:23 Mooers, Blaine H.M. (HSC) <Bla...@ou...> ha scritto: > Hi Lorenzo, > > You can import numpy and replace your lists of coordinates with NumPy arrays. > Operations with numpy arrays can be >100 times faster than with lists in for loops. > See the last example the following blog post for inspiration: > > https://medium.freecodecamp.org/if-you-have-slow-loops-in-python-you-can-fix-it-until-you-cant-3a39e03b6f35. > > Please recall that PyMOL is collection of C and C++ programs wrapped by Python. > The fast display of bonds inside the viewport is due to C or C++ programs. > > Best regards, > > Blaine > > Blaine Mooers, Ph.D. > Associate Professor > Department of Biochemistry and Molecular Biology > College of Medicine > University of Oklahoma Health Sciences Center > S.L. Young Biomedical Research Center (BRC) Rm. 466 > 975 NE 10th Street, BRC 466 > Oklahoma City, OK 73104-5419 > > ________________________________________ > From: Lorenzo Gaifas [br...@gm...] > Sent: Saturday, May 25, 2019 5:48 AM > To: pym...@li... > Subject: [EXTERNAL] [PyMOL] Absymal performance when creating large numbers of bonds > > Dear pymol users, > > I'm working on a script, using the python API, that needs to add a very large number of bonds to the loaded structure. > > I thought simply using cmd.bond() in a for loop would do the trick, but -even though it works- it is extremely slow. I figured something was fishy, since pymol at startup is almost istantaneous and there, too, it has to compute, draw and even guess equally large numbers of bonds. > > I also tried to parallelise the command, but by now I *think* this can't be done due to the Global Intepreter Lock. > > I feel like there must be something I'm missing (maybe a way to prevent pymol from updating the rendering between each cmd.bond call?) or at least an API function that better exposes the bond generation procedure. Does someone have suggestions on how to solve this problem? > > Cheers, > Lorenzo > _______________________________________________ > PyMOL-users mailing list > Archives: http://www.mail-archive.com/pym...@li... > Unsubscribe: https://sourceforge.net/projects/pymol/lists/pymol-users/unsubscribe -- Thomas Holder PyMOL Principal Developer Schrödinger, Inc. |