so there is a big trouble in my script : I have done an array with numpy with contains x,y and z coordinates of some points. some of these points have negative coordinates (for x and/or y and/or z). And for reasons I don't understand, when I use the function scatter from matplotlib, it plots all points with positives coordinates (it means that if a coordinate is negative, it will be plotted as positive...):
So my question is simple : why does it do that, and how to plot points with negatives coordinates properly ?
Here is my code in 2 parts :
#!/usr/bin/python
# -*- coding: utf-8 -*-
import Tkinter
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
import numpy as np
import os
import subprocess
import Parse_Gro
class windowsTk(Tkinter.Tk):
def __init__(self,parent):
Tkinter.Tk.__init__(self,parent)
self.parent = parent
self.f = Figure(figsize=(6, 6), dpi=100)
self.canevas = FigureCanvasTkAgg(self.f, master=self)
self.subplota= self.f.add_subplot(111)
self.RotateMatY= np.matrix([[np.cos(0.2*np.pi),0,np.sin(0.2*np.pi)],[0,1,0],[-np.sin(0.2*np.pi),0,np.cos(0.2*np.pi)]])
self.RotateMatZ= np.matrix([[np.cos(0.2*np.pi),-np.sin(0.2*np.pi),0],[np.sin(0.2*np.pi),np.cos(0.2*np.pi),0],[0,0,1]])
self.matrice=Parse_Gro.get_Coordinates()
self.initialize()
def initialize(self):
self.grid()
self.canevas.get_tk_widget().grid(column=0,row=0,columnspan=3)
button1 = Tkinter.Button(self,text=u"Rotate Right",command=self.ClickonRight)
button1.grid(column=2,row=2)
button2 = Tkinter.Button(self,text=u"Rotate Left",command=self.ClickonLeft)
button2.grid(column=0,row=2)
button3 = Tkinter.Button(self,text=u"Rotate Up",command=self.ClickonUp)
button3.grid(column=1,row=1)
button4 = Tkinter.Button(self,text=u"Rotate Down",command=self.ClickonDown)
button4.grid(column=1,row=3)
#Sort according to X coordinate (first column)
#self.matrice=np.sort(self.matrice, axis=0)
#Scatter Plot Test
self.subplota.scatter(self.matrice[:,1],self.matrice[:,2],c=self.matrice[:,0],s=self.matrice[:,0]*100)
def ClickonRight(self):
print"Right Rotation"
def ClickonLeft(self):
print"Left Rotation"
def ClickonUp(self):
print"Up Rotation"
def ClickonDown(self):
print"Down Rotation"
if __name__ == "__main__":
app = windowsTk(None)
app.title('Visualisation 3D Proteine')
app.mainloop()
here is the second part of the code in an other file.py
:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import subprocess
import numpy as np
def get_Coordinates():
path = raw_input("Enter a Path to your PDB file: ")
#Path Example :/home/yoann
os.chdir(path)
filename = raw_input("Enter the name of your PDB file: ")
#Filename Example : 5f4c.pdb
bashCommand = "gmx editconf -f {:s} -o output.gro -center 0 0 0 -aligncenter 0 0 0".format(filename)
process = subprocess.Popen(bashCommand.split(), stdout=subprocess.PIPE)
output = process.communicate()[0]
ListX=[]
ListY=[]
ListZ=[]
with open("/home/yoann/output.gro","r") as file:
lines = file.readlines()
for line in lines[2:-1:]:
ListX.append(float(line[22:28]))
ListY.append(float(line[30:36]))
ListZ.append(float(line[38:44]))
matrixCoord=np.column_stack([ListX,ListY,ListZ])
return matrixCoord
Here I put an example of the content of the File red by the function get_Coordinate() :
PUTATIVE CYTOPLASMIC PROTEIN
1637
1MET N 1 1.206 1.701 1.641
1MET CA 2 1.077 1.663 1.575
2ASN C 11 0.687 1.503 1.675
2ASN O 12 0.688 1.495 1.550
Here I put what should show the program :
Cheers !