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 [bris...@gmail.com] Sent: Saturday, May 25, 2019 5:48 AM To: pymol-users@lists.sourceforge.net 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/pymol-users@lists.sourceforge.net Unsubscribe: https://sourceforge.net/projects/pymol/lists/pymol-users/unsubscribe