This is a test version of Biostars. For the public version, visit https://www.biostars.org.
In this Python script I want to save result of print(traj_rmsd) in an output.xvg file. I am unable to open this file and it's showing following message:

In this Python script I want to save result of print(traj_rmsd) in an output.xvg file. I am unable to open this file and it's showing following message:

File type unknown (application/octet-stream) is not supported I don't know whether it's a problem in the script or what. I have tried it on Ubuntu 16 and I only have gedit text editor. The Python version I'm using is 3.5

This is my Python script:

import mdtraj
import numpy 
# Parse the input data.
traj = mdtraj.load('rmsd.xtc', top='rmsd.gro')
traj_rmsd=mdtraj.rmsd(traj,traj[0], atom_indices=None, parallel=True, precentered=False)
# Print and save the answer.
print (traj_rmsd)
with open('output.xvg', 'wb') as output_data:
    output_data.write(traj_rmsd)
mdtraj python molecular dyanamics

Well for one thing you don't need 'wr' in your with statement if you're just writing to the file

Can you print the stacktrace?

i have change script , actually i want to save my result of print(traj_rmsd) as a output file in this script i am getting output file as 'output.text' but itz not readable....

ok, well if you post the code that is actually used and the error that is actually generated, then i will help you with the problem that you actually have :)

You are writing it as a binary file ('wb'). Is that what you wanted to do? If you want to open it as text, just use 'w' instead of 'wb'.

@ damian if i will use"w" instead of "wb" it will showing this error... TypeError: write() argument must be str, not numpy.ndarray

Well there is your problem. You first need to convert the numpy.ndarray to a string or multiple strings.

@ wouter can you suggest me how to convert numpy.ndarray to a string or multiple strings.

Devon Ryan posted how to get help with saving numpy array data. In your python terminal, run help(numpy.savetxt)

@devon when i typed help(numpy.savetxt) in python terminal it showing following error NameError: name 'numpy' is not defined

Probably a long shot, I've never tried it, but does output_data.write(str(traj_rmsd)) work?

help(numpy.savetxt)

0 answers

No answers yet.

Log in to answer this question.