Atomselection in sphlayer and sphzone non consistent

11 views
Skip to first unread message

Joan Garcia i Masferrer

unread,
Nov 30, 2023, 7:59:52 AM11/30/23
to MDnalysis discussion
Hy everyone.
Im working on a project where I need to calculate the radial density of a set compound/ atom or molecule.
In order to do it I want the program to count the number of atoms in between two spheres, centered in a set object, that progressively change their radius and calculate the density using that information.
The main problem that appears is that the atom selection does not work as I expected as it does not select the atoms correctly I also must mention that the position of the AND operator changes the result (as in : (type OT and sphlayer {a} {b} (resname BDC)) /diferent from/ (sphlayer {a} {b} (resname BDC) and type OT )).
Therefore I would like to know how do the sphlayer and sphzone selections exactly work. (I copy the program below).
Thanks in advance, best regards.


CODE:
import MDAnalysis as mda
import numpy as np


list_radius = []
list_density = []



def fun_density(): #Calculates the density vs radius of a set kind of atom in the system
   
    b = 1.0 #Exterior radius
    a = 0.0 #Interior radius
    R = 25 #Final radius

    f = open('Radial_density.txt','w') #Txt archive name
   
    while b <= R and a < b:
          atoms_int= u.select_atoms(f'type OT and sphlayer {a} {b} (resname BDC)')
         
          print(len(atoms_int))
          Density = 1000*(len(atoms_int)/((4/3)*np.pi*b**3-(4/3)*np.pi*a**3)) #Densitat en atoms/nm^3
         
          list_density.append(f"{Density}")
          list_radius.append(f'{a}')
         
          f.write(f'{b} {Density}\n')
         
          b+=0.01 #Set the resolution
         
          a+=0.01 #set the resolution
     
    f.close()


u = mda.Universe('system.psf', 's1_NpT.dcd') #change solvate.psf for the system's name

fun_density()
Reply all
Reply to author
Forward
0 new messages