class GlobalPyMOL: """ SingletonPyMOL that works like the parallel but that waits for the other thread to release it. Use with a context manager! """ pymol = pymol2.SingletonPyMOL() pymol.start() pymol.cmd.set('fetch_path', tempfolder) pylock = Lock() def __init__(self): pass def __enter__(self): if not self.pylock.acquire(timeout=60): # something hung up. self.pymol.cmd.remove('*') self.pymol.cmd.delete('*') self.pylock.release() #pointless roundtrip to be safe. self.pylock.acquire() return self.pymol else: self.pymol.cmd.delete('*') return self.pymol def __exit__(self, exc_type, exc_val, exc_tb): self.pymol.cmd.delete('*') self.pylock.release() def kill(self): ## the assumption is that it died. self.pymol.cmd.reinitialize() #dangerous for other threads. if self.pylock.locked(): self.pylock.release()
def _launch_no_gui(): import pymol2 p = pymol2.SingletonPyMOL() p.start() # TODO sufficient? while (p.idle() or p.getRedisplay() or invocation.options.keep_thread_alive or cmd.get_modal_draw() or cmd.get_setting_int('keep_alive') or cmd._pymol._stdin_reader_thread is not None): p.draw() # TODO needed? cmd.sync() p.stop()
if self.fuser.debug: print(f'Final position for model {self.name}.....') self.describe() return self def roll(self, φ): """ Whereas they are aligned on the x-axis with the y,z coordinates of C and N termini near 0,0. They can rotate around the X. roll. This is good to remove clashes. """ self.pymol.cmd.rotate([1, 0, 0], φ, selection=self.name, camera=0) self.angle_fix() return self if __name__ == '__main__': import pymol2, argparse parser = argparse.ArgumentParser( description='Combine structures for a Uniprot') parser.add_argument('uniprot', type=str, help='Uniprot to generate a combined model') args = parser.parse_args() with pymol2.SingletonPyMOL() as pymol: Fuser.pymol = pymol w = Fuser.from_uniprot(args.uniprot, debug=False) w.order() w.save() #w.add_xyz()