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:
0
0
Entering edit mode
7.9 years ago

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 • 3.4k views
ADD COMMENT
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

Can you print the stacktrace?

ADD REPLY
0
Entering edit mode

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....

ADD REPLY
0
Entering edit mode

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 :)

ADD REPLY
0
Entering edit mode

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'.

ADD REPLY
0
Entering edit mode

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

ADD REPLY
1
Entering edit mode

help(numpy.savetxt)

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

You need to import numpy first.

ADD REPLY
0
Entering edit mode

@wouter , thanks now itz working

ADD REPLY
0
Entering edit mode

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

ADD REPLY

Login before adding your answer.

Traffic: 1737 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6