Pymol not outputting image - python

I am trying to draw a protein structure from a pdb file using pymol.
However, when I try to run the script below, a pymol window opens but it is just pitch black. Also, bizarrely, the pdb file is outputted to the shell.
Here is my code:
bioservices_pdb_obj = PDB()
pdb_file = bioservices_pdb_obj.getFile(results[str(Brick.part_attrib(self,'uniprot_id'))][detail-1],'pdb')
pdb_name = str(Brick.part_attrib(self,'uniprot_id'))
pymol.finish_launching()
pymol.cmd.load(pdb_file, pdb_name)
pymol.cmd.disable("all")
pymol.cmd.enable(pdb_name)
pymol.cmd.png("my_pdb.png")
pymol.cmd.quit()
Does anyone know what is going on here?
The .png file 'my_pdb' is dumped into the working directory, but that's just black as well.

Does this also happen with any other PDB file? If yes, you can try a workaround using the cmd.mpng() function. You can use this function also in other contexts if the cmd.png() function doesn't work, e.g. when using PyMOL in command-line mode.
import pymol
from pymol import cmd
import os
pymol.finish_launching()
cmd.set('ray_trace_frames', 1) # Frames are raytraced before saving an image.
def pnghack(filepath, width=1024, height=768):
"""Workaround if cmd.png() doesn't work"""
cmd.viewport(width, height) # Set resolution
cmd.mpng(filepath, 1, 1) # Use batch png mode with 1 frame only
cmd.mplay() # cmd.mpng needs the animation to 'run'
cmd.load(pdb_file, pdb_name)
cmd.disable("all")
cmd.enable(pdb_name)
pnghack("my_pdb.png")
cmd.quit()
Note that the resulting png file is named "my_pdb0001.png" as the cmd.mpng() function always adds the framenumber.

Related

the algorithm don't display the mesh

I am using Jupyter in a Conda environment:
import igl
import meshplot as mp
import numpy as np
v, f = igl.read_triangle_mesh("./earth.ply")
k = igl.gaussian_curvature(v, f)
mp.plot(v, f, k, return_plot = True)
OUTPUT:
<meshplot.Viewer.Viewer at 0x1b53eb03fa0>
it is not displaying the mesh. it just outputs the location it stored in memory. Please help me.
It seems that you have your meshplot.rendertype set to "OFFLINE".
If you are using this code in a jupyter notebook and want to display the mesh, then just switch rendertype to "JUPYTER", by executing mp.jupyter() somewhere before your plot() command.
If you are running the code as a normal python program, you can export this View object as a HTML frame using the View.to_html() method. Then you can insert this frame into a html file and view it in a browser.
You can check out the source code for switching rendertype here, how the mp.plot function works here. The View class with the to_html method is defined here.

Unimplemented OBJ format statement 's' on line 's 1' ERROR

hi i am going to import an OBJ 3d File using Pywavefront library and Display this 3d Model on another 3d scene finally. I studied about this library and 3d Models much.
import pywavefront
import pywavefront.visualization
from pywavefront import visualization
from pywavefront import material
from pywavefront import mesh
from pywavefront import parser
import pywavefront.texture as texture
my obj file named "low-poly-fox-by-pixelmannen" that i downloaded from Clara.io website along its MTL file and added to my pycharm Working Dir both of files.
my codes for import this obj file as:
fox = pywavefront.Wavefront('low-poly-fox-by-pixelmannen.obj', collect_faces=True)
I would like to display this obj file into pycharm, but after Run, program shows ONLY a EMPTY WHITE SCREEN and says this ERROR:
Unimplemented OBJ format statement 's' on line 's 1'
Important point is: when pycharm runs and white screen appeared pycharm Thinking still and pycharm CRASH.
I am CONFUSED from Yesterday and Searched Similar errors, but I didnt find Any Solution or Comment about My problem. Please tell me what means this error? and Guide me for solve problem and Display 3d OBJ file finally.
It means you have a problem with the file which contains smooth shading statements (read here for more https://en.wikipedia.org/wiki/Wavefront_.obj_file).
Pywavefront does not know what is it (it is not implemented in their parser as I see).
So you can comment this line (# s 1), so it will not be parsed.
About visualization, I think that your problem is not with this error. According to their main parser class, it should raise an error only if you add to loader strict=True parameter (it is False by default). So I think your model is loaded w\o smooth shading, but the problem with visualization does not correspond with that error (it just warns you - logged).
I can have an assumption that you do not install or import some module that provides vizualisation.
You asked this question about 2 months ago, if you find the solution, It would be nice to share it :)

How to store the last displayed value from the console?

My python script passes changing inputs to a program called "Dymola", which in turn performs a simulation to generate outputs. Those outputs are stored as numpy arrays "out1.npy".
for i in range(0,100):
#code to initiate simulation
print(startValues, 'ParameterSet:', ParameterSet,'time:', stoptime)
np.save('out1.npy', output_data)
Unfortunately, Dymola crashes very often, which makes it necessary to rerun the loop from the time displayed in the console when it has crashed (e.g.: 50) and increase the number of the output file by 1. Otherwise the data from the first set would be overwritten.
for i in range(50,100):
#code to initiate simulation
print(startValues, 'ParameterSet:', ParameterSet,'time:', stoptime)
np.save('out2.npy', output_data)
Is there any way to read out the 'stoptime' value (e.g. 50) out of the console after Dymola has crashed?
I'm assuming dymola is a third-party entity that you cannot change.
One possibility is to use the subprocess module to start dymola and read its output from your program, either line-by-line as it runs, or all after the created process exits. You also have access to dymola's exit status.
If it's a Windows-y thing that doesn't do stream output but manipulates a window GUI-style, and if it doesn't generate a useful exit status code, your best bet might be to look at what files it has created while or after it has gone. sorted( glob.glob("somepath/*.out")) may be useful?
I assume you're using the dymola interface to simulate your model. If so, why don't you use the return value of the dymola.simulate() function and check for errors.
E.g.:
crash_counter = 1
from dymola.dymola_interface import DymolaInterface
dymola = DymolaInterface()
for i in range(0,100):
res = dymola.simulate("myModel")
if not res:
crash_counter += 1
print(startValues, 'ParameterSet:', ParameterSet,'time:', stoptime)
np.save('out%d.npy'%crash_counter, output_data)
As it is sometimes difficult to install the DymolaInterface on your machine, here is a useful link.
Taken from there:
The Dymola Python Interface comes in the form of a few modules at \Dymola 2018\Modelica\Library\python_interface. The modules are bundled within the dymola.egg file.
To install:
The recommended way to use the package is to append the \Dymola 2018\Modelica\Library\python_interface\dymola.egg file to your PYTHONPATH environment variable. You can do so from the Windows command line via set PYTHONPATH=%PYTHONPATH%;D:\Program Files (x86)\Dymola 2018\Modelica\Library\python_interface\dymola.egg.
If this does not work, append the following code before instantiating the interface:
import os
import sys
sys.path.insert(0, os.path.join('PATHTODYMOLA',
'Modelica',
'Library',
'python_interface',
'dymola.egg'))

Maya - Using Python to render a sequence

I am making a test render script in Python and am having problems getting my render calls to output sequences, and not just one frame.
I am working in Maya 2015 on a Windows 7 machine.
I have tried using the ogsRender() (Hardware 2.0) and render() (Software Render) commands. And while both of them proclaim to be able to output sequences in the docs, I can't seem to get them to do so.
import maya.cmds as cmds
cmds.render()
cmds.ogsRender()
Being a test render script, it doesn't need to be pretty--just fast.
hwRender() (old Hardware Render) seems to work fine, outputting frames according to render settings. However, I get a lot of white artifacts from any intersections when using that render, making it hard to see if things are correct.
Does anyone know how to get render() or ogsRender() to output sequences?
Or maybe remove the white artifacts hwRender() produces?
Thanks for your time!
Just incase this is what you're after, here's a rough approach you could use where you jog the frame and make your own batch-ish render system.
The only reason I've used renderfn rather than hardcoding maya.cmds.render is just incase you wanted to hook into something else (like, I dunno, dropping out some kind of scenefile that you'd feed into a renderfarm or suchlike)
import maya.cmds as mc
def render_seq(startframe = 1, endframe = 10, renderfn = mc.render, renderfn_args = None):
'''render out a sequence of frames as per global settings
defaults to using maya.cmds.render for frames 1-10'''
# save state
now = mc.currentTime(q=True)
for x in xrange(startframe, endframe):
mc.currentTime(x)
renderfn(renderfn_args)
# restore state
mc.currentTime(now)

Auto threshold in ImageJ/FIJI with Python

I'm trying to write python scripts in ImageJ and I'm having problems with autothresholding. It won't let me use the IJ.setAutoThreshold("Default dark"). An example bit of code is below (with a few things left out for clarity):
from ij import IJ, ImagePlus
from java.lang import Runtime, Runnable
import os
for i in filepaths: #filepaths being the files I'm opening
IJ.open(i)
IJ.run("Split Channels") #this is splitting a two channel image
imp = IJ.getImage()
imp.close() #this is closing the channel I don't want
IJ.setAutoThreshold("Default dark") #this is trying to set a threshold
Setting the auto threshold here gives
AttributeError: type object 'ij.IJ' has no attribute 'setAutoTrheshold'
How can I access ImageJ's threshold function?
Cheers!
Have a look at the javadoc: IJ has a method taking two arguments
setAutoThreshold(ImagePlus imp, String method)
so in your case
IJ.setAutoThreshold(imp, "Default dark")
should work.

Categories