Commit af5a1399 authored by Francisco Javier Dominguez Gutierrez's avatar Francisco Javier Dominguez Gutierrez
Browse files

Add new file

parent 5fb945bc
import numpy as np
from pylab import *
from numpy import *
import linecache
import matplotlib.pyplot as plt
from sklearn.decomposition import TruncatedSVD
num_atom = 314928
i = 0
arr = []
dist_diff = []
# Cleaning quip output file
# Start reading DV at line 13
for i in range(13,13+num_atom):
dv_1 = np.array(linecache.getline('../vectors.dat',i)[7::].split())
dv = dv_1.astype(np.float)
arr.append(dv)
ref_v = np.loadtxt('id_atoms.dat')
lent1 = len(ref_v)
Ar = []
for d in range(0,lent1):
i = int(ref_v[d])
Ar.append(arr[i])
Ar = np.array(Ar)
ffile = open('new_type.dat','w')
for i in range(0,50):
ffile.write("{} {} \n".format(i,Ar[0,i]))
#computing mean value of each component column
A_m = np.mean(Ar.T,axis=1)
Ap = Ar-A_m
# svd
svd = TruncatedSVD(n_components=2)
svd.fit(Ap)
result = svd.transform(Ap)
thefile = open('pca_results.dat','w')
lengt = len(result[:,0])
print("lengt of the truncated vector: {0}".format(lengt))
for i in range(0,lengt):
thefile.write("{0} {1} {2} \n".format(-result[i,0],' ', -result[i,1]))
fig, ax = plt.subplots()
rc('axes', linewidth=2)
plt.scatter(-result[:,0],-result[:,1],alpha=1.00,color="blue",marker="x",s=50,linewidth=2)
circl = plt.Circle((0.03,-0.001),0.055,color='black',fill=False,linewidth=2)
ax.add_artist(circl)
ax.xaxis.get_major_ticks()
plt.xlim(-0.4,0.3)
plt.ylim(-0.2,0.2)
plt.text(0.20,0.15,'a)',fontsize=35)
plt.xlabel('Principal Component 1 ', fontsize=12)
plt.ylabel('Principal Component 2 ', fontsize=12)
for axis in ['top','bottom','left','right']:
ax.spines[axis].set_linewidth(1.5)
plt.savefig('pca_svd.png',format='png',dpi=1000)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment