title: Trajectory file analysis using Python
body: <p>First of all, I am very new to python.
  I have a large trajectory file with multi-time steps (50000) and what I am trying to do is write a python code which calculates the mean square displacement of water Oxygen(O) atoms.</p>
  <p>My plan is to first select Oxygen atoms frame by frame and then carry out with the MSD code. In a single frame of my trajectory file the first 2 lines contains the total number of atoms(5058) and atom description respectively for that perticular frame, after that the next 606 lines contain the surface atoms and the remaining 4450 lines contain the water atoms in an orderly manner(O,H,H,O,H,H,O,H,H, etc) I started like this but I feel like I am going nowhere.</p>
  <pre class="lang-py prettyprint-override"><code>  import numpy as np 
    import math
    
    #parameters
   
   
   m_o     = 16 #gmol-1                                                  
   m_h     = 1 #gmol-1
   leave   = 608 #including the two title lines first 606 atoms are surface atms.so they should be just read
   waters  = 4450 #after the first 606 atoms the rest are water atoms
   N       = 5060 #number of lines in a frame
   
   
   with open(&quot;traj.xyz&quot;,&quot;r&quot;) as f:
      count = len(f.readlines(  )) #counts the total number of lines
   #print(count)
   nof = count/N
   '''nof is number of frames'''
   print(int(nof))
   
   def frames():
      for i in nof:
          count = 0
          xcoord = []
          ycoord = []
          zcoord = []
          for i in range(leave):
              title = f.readline()
              for line in f:
                  cnt+=1
                  if (cnt % 3 == 1):
                      atmid,x,y,z = line.split()
                      xcoord.append(x)
                      ycoord.append(y)
                      zcoord.append(z)
                      print(atmid,x,y,z)
  
   if (cnt == waters):
      exit()                                                                
   frames()
  </code></pre>