def plot_kmumu_mass(data_frame, to_plot): """ Plots the pikmumu mass where the proton has a pion hypothesis :param data_frame: :param to_plot: :return: """ particles_associations = [['Kminus_P', 'K'], ['mu1_P', 'mu'], ['tauMu_P', 'mu']] data_frame['kmumu_mass'] = get_mass( data_frame=data_frame, particles_associations=particles_associations) particles_associations = [['proton_P', 'K'], ['mu1_P', 'mu'], ['tauMu_P', 'mu']] data_frame['p(k)mumu_mass'] = get_mass( data_frame=data_frame, particles_associations=particles_associations) particles_associations = [['Kminus_P', 'K'], ['mu1_P', 'mu'], ['proton_P', 'mu']] data_frame['kmup(mu)_mass'] = get_mass( data_frame=data_frame, particles_associations=particles_associations) if to_plot: plt.hist(data_frame['kmumu_mass'], bins=100) plt.xlabel('$m_{k\\mu\\mu}$') plt.ylabel('occurrences') plt.show() plt.hist(data_frame['p(k)mumu_mass'], bins=100) plt.xlabel('$m_{p(k)\\mu\\mu}$') plt.ylabel('occurrences') plt.show() plt.hist(data_frame['kmup(mu)_mass'], bins=100) plt.xlabel('$m_{k\\mu p(\\mu )}$') plt.ylabel('occurrences') plt.show() return data_frame
def masses(self): masses = [] for atom in self.mol.atoms: masses.append(1 / np.sqrt(get_mass(atom))) masses.append(1 / np.sqrt(get_mass(atom))) masses.append(1 / np.sqrt(get_mass(atom))) M = np.diag(masses) return M
def masses(self): masses = [] for atom in self.mol.atoms: masses.append(1/np.sqrt(get_mass(atom))) masses.append(1/np.sqrt(get_mass(atom))) masses.append(1/np.sqrt(get_mass(atom))) M = np.diag(masses) return M
def frequencies(filename, units='Angstrom'): hess_list = [] with open(filename, 'r') as fn: for line in fn: hess_list.append(line.split()) hess = np.array(hess_list).astype(float) mol = molecule(filename='molecule.xyz', units=units) mol.to_angstrom() mw_hess = hess.copy() shape = mw_hess.shape for i in range(len(mol.labels)): for j in range(len(mol.labels)): a1 = mol.labels[i] a2 = mol.labels[j] m1 = get_mass(a1) m2 = get_mass(a2) for k in range(3): for l in range(3): mw_hess[(3 * i + k)][( 3 * j + l)] = hess[(3 * i + k)][(3 * j + l)] / ((m1 * m2)**0.5) eig = np.linalg.eigh(mw_hess) mass_matrix = np.zeros(shape) mass_list = [] for i in mol.labels: for j in range(3): mass_list.append(get_mass(i)) for i in range(len(mass_list)): mass_matrix[i][i] = (mass_list[i])**(-0.5) q = np.dot(mass_matrix, eig[1]) force_constants = (np.lib.scimath.sqrt(eig[0] * (4.35974e-18) * ((1.89e10)**2) * (6.022e26)) / (2 * np.pi)) / (3e10) fc_strings = [] for i in range(len(force_constants)): if np.real(force_constants[i]) == 0.0: fc_strings.append('{}i'.format(np.imag(force_constants[i]))) else: fc_strings.append('{}'.format(np.real(force_constants[i]))) fout = open('normal_modes.xyz', 'w') for i in range(shape[0]): fout.write( str(mol.natom) + '\n' + '{}. Frequency: {} cm^-1'.format(i, fc_strings[i]) + '\n') for j in range(len(mol.labels)): string = '{} {:10f} {:10f} {:10f} {:10f} {:10f} {:10f}'.format( mol.labels[j], mol.geom[j][0], mol.geom[j][1], mol.geom[j][2], q[3 * j, i], q[(3 * j + 1), i], q[(3 * j + 2), i]) fout.write(string + '\n') fout.write('\n') fout.close()
def plot_ppimumu_mass(data_frame, to_plot): """ Plots the pikmumu mass where the proton has a pion hypothesis :param data_frame: :param to_plot: :return: """ particles_associations = [['Kminus_P', 'pi'], ['proton_P', 'proton'], ['mu1_P', 'mu'], ['tauMu_P', 'mu']] data_frame['ppimumu_mass'] = get_mass( data_frame=data_frame, particles_associations=particles_associations) particles_associations = [['Kminus_P', 'pi'], ['proton_P', 'proton']] data_frame['ppi_mass'] = get_mass( data_frame=data_frame, particles_associations=particles_associations) if to_plot: test_data = data_frame[(data_frame['ppimumu_mass'] > 5400) & (data_frame['ppimumu_mass'] < 5600)] plt.hist(data_frame['ppimumu_mass'], bins=150, range=[4000, 7000]) plt.hist( data_frame[(data_frame['Lb_M'] > 5620 - 40) & (data_frame['Lb_M'] < 5620 + 40)]['ppimumu_mass'], bins=150, range=[3000, 7000]) plt.axvline(masses['Lb'], c='k') plt.xlabel('$m_{p\\pi\\mu\\mu}$') plt.ylabel('occurrences') plt.show() plt.hist(data_frame['ppi_mass'], bins=100, range=[1000, 3000]) plt.xlabel('$m_{p\\pi}$') plt.ylabel('occurrences') plt.axvline(1115, c='k') plt.show() plt.hist(test_data['ppi_mass'], bins=100, range=[1000, 3000]) plt.xlabel('$m_{p\\pi}$') plt.ylabel('occurrences') plt.axvline(1115, c='k') plt.show() plt.hist2d(data_frame['ppimumu_mass'], data_frame['ppi_mass'], bins=30, range=[[3000, 7000], [1000, 4000]]) plt.xlabel('$m_{p\\pi\\mu\\mu}$') plt.ylabel('$m_{p\\pi}$') plt.axvline(masses['Lb'], c='k') plt.axhline(1115, c='k') plt.show() plt.hist2d(data_frame['ppimumu_mass'], data_frame['Lb_M'], bins=60, range=[[3000, 7000], [3000, 7000]]) plt.xlabel('$m_{p\\pi\\mu\\mu}$') plt.ylabel('$m_{Lb}$') plt.show() data_frame = data_frame[(data_frame['ppimumu_mass'] < 5420) | (data_frame['ppimumu_mass'] > 5620)] return data_frame
def plot_kkmumu_mass(data_frame, to_plot): """ Plots the pikmumu mass where the proton has a pion hypothesis :param data_frame: :param to_plot: :return: """ particles_associations = [['Kminus_P', 'K'], ['proton_P', 'K'], ['mu1_P', 'mu'], ['tauMu_P', 'mu']] data_frame['kkmumu_mass'] = get_mass( data_frame=data_frame, particles_associations=particles_associations) particles_associations = [['Kminus_P', 'K'], ['proton_P', 'K']] data_frame['kk_mass'] = get_mass( data_frame=data_frame, particles_associations=particles_associations) if to_plot: plt.hist(data_frame['kkmumu_mass'], bins=100, range=[2500, 7000]) plt.xlabel('$m_{KK\\mu\\mu}$') plt.ylabel('occurrences') plt.axvline(5366, c='k') # Bs mass plt.show() test_data = data_frame[(data_frame['kkmumu_mass'] > 5366 - 100) & (data_frame['kkmumu_mass'] < 5366 + 100)] plt.hist(data_frame['kk_mass'], bins=100, range=[900, 2000]) plt.xlabel('$m_{KK}$') plt.ylabel('occurrences') plt.axvline(1020, c='k') plt.show() plt.hist(test_data['kk_mass'], bins=100, range=[900, 2000]) plt.xlim(right=2000) plt.xlabel('$m_{KK}$') plt.ylabel('occurrences') plt.axvline(1020, c='k') plt.show() plt.hist(test_data['kkmumu_mass'], bins=100) plt.xlim(right=7000) plt.xlabel('$m_{KK\\mu\\mu}$') plt.ylabel('occurrences') plt.axvline(5366, c='k') plt.show() plt.hist2d(data_frame['kkmumu_mass'], data_frame['kk_mass'], bins=30, range=[[2000, 7000], [900, 2000]]) plt.axvline(5366, c='k') plt.axhline(1020, c='k') plt.xlabel('$m_{KK\\mu\\mu}$') plt.ylabel('$m_{KK}$') plt.show() to_drop = data_frame[((data_frame['kkmumu_mass'] > 5366 - 200) & (data_frame['kkmumu_mass'] < 5366 + 200)) & ((data_frame['kk_mass'] > 990) & (data_frame['kk_mass'] < 1050))] data_frame = data_frame.drop(to_drop.index) return data_frame
def kmu_cut(data_frame: pd.DataFrame, to_plot: bool = False) -> pd.DataFrame: """ Cuts on the kmu mass, where we assume a decay of the type Lb -> p D0 (-> K mu nu) mu nu If to_plot is true, we also show the Kpi mass plot (where we assume Lb -> p D0 (-> K pi) pi) :param data_frame: data frame to cut on :param to_plot: if True, plots the Kpi mass and the Kmu mass, where the particles have opposite charges :return: """ data_frame['kpi1_mass'] = get_mass( data_frame, particles_associations=[['Kminus_P', 'K'], ['mu1_P', 'pi']]) data_frame['ktaupi_mass'] = get_mass( data_frame, particles_associations=[['Kminus_P', 'K'], ['tauMu_P', 'pi']]) data_frame['kmu1_mass'] = get_mass( data_frame, particles_associations=[['Kminus_P', 'K'], ['mu1_P', 'mu']]) data_frame['ktauMu_mass'] = get_mass( data_frame, particles_associations=[['Kminus_P', 'K'], ['tauMu_P', 'mu']]) if to_plot: plt.hist([ data_frame[np.sign(data_frame['Kminus_ID']) == np.sign( data_frame['mu1_ID'])]['kpi1_mass'], data_frame[np.sign(data_frame['Kminus_ID']) == np.sign( data_frame['tauMu_ID'])]['ktaupi_mass'] ], bins=100, stacked=True, color=['C0', 'C0']) plt.axvline(masses['D0'], c='k') plt.xlabel('$m_{K\\pi}$') plt.show() plt.hist([ data_frame[np.sign(data_frame['Kminus_ID']) == np.sign( data_frame['mu1_ID'])]['kmu1_mass'], data_frame[np.sign(data_frame['Kminus_ID']) == np.sign( data_frame['tauMu_ID'])]['ktauMu_mass'] ], bins=100, stacked=True, color=['C0', 'C0']) plt.axvline(masses['D0'], c='k') plt.xlabel('$m_{K\\mu}$') plt.show() to_drop_1 = data_frame[ (np.sign(data_frame['Kminus_ID']) == np.sign(data_frame['mu1_ID'])) & (data_frame['kmu1_mass'] < masses['D0'])] to_drop_2 = data_frame[ (np.sign(data_frame['Kminus_ID']) == np.sign(data_frame['tauMu_ID'])) & (data_frame['ktauMu_mass'] < masses['D0'])] data_frame = data_frame.drop(list(to_drop_1.index)) data_frame = data_frame.drop(list(to_drop_2.index)) return data_frame
def plot_pikmumu_mass(data_frame, to_plot): """ Plots the pikmumu mass where the proton has a pion hypothesis :param data_frame: :param to_plot: :return: """ particles_associations = [['Kminus_P', 'K'], ['proton_P', 'pi'], ['mu1_P', 'mu'], ['tauMu_P', 'mu']] data_frame['pikmumu_mass'] = get_mass( data_frame=data_frame, particles_associations=particles_associations) particles_associations = [['Kminus_P', 'K'], ['proton_P', 'pi']] data_frame['pik_mass'] = get_mass( data_frame=data_frame, particles_associations=particles_associations) if to_plot: # data_frame = data_frame[(data_frame['Lb_M'] < 5620 - 40) | (data_frame['Lb_M'] > 5620 + 40)] plt.hist(data_frame['pikmumu_mass'], bins=100, range=[3500, 6500]) plt.axvline(masses['B'], c='k') plt.axvline(5366, c='k') # Bs mass plt.xlabel('$m_{K\\pi\\mu\\mu}$') plt.ylabel('occurrences') plt.show() test_part = data_frame[ (data_frame['pikmumu_mass'] < masses['B'] + 100) & (data_frame['pikmumu_mass'] > masses['B'] - 100)] plt.hist(data_frame['pik_mass'], bins=50, range=[500, 2000]) plt.axvline(masses['kstar'], c='k') plt.xlabel('$m_{K\\pi}$') plt.ylabel('occurrences') plt.show() plt.hist(test_part['pik_mass'], bins=100, range=[500, 2000]) plt.axvline(masses['kstar'], c='k') plt.xlabel('$m_{K\\pi}$') plt.ylabel('occurrences') plt.show() plt.hist2d(data_frame['pikmumu_mass'], data_frame['pik_mass'], bins=30, range=[[2000, 7000], [500, 2000]]) plt.xlabel('$m_{K\\pi\\mu\\mu}$') plt.ylabel('$m_{K\\pi}$') # plt.savefig('pikmumu_pik_nolb.png') plt.show() to_remove_b = data_frame[( (data_frame['pikmumu_mass'] < 5366 + 200) & (data_frame['pikmumu_mass'] > masses['B'] - 200)) & ( (data_frame['pik_mass'] > masses['kstar'] - 30) & (data_frame['pik_mass'] < masses['kstar'] + 30))] data_frame = data_frame.drop(to_remove_b.index) return data_frame
def __init__(self, xyzfile): with open(xyzfile, "r") as f: lines = f.readlines() #opening the xyz file for reading self.xyz = xyzfile self.natom = int(lines[0]) #first line = num of atoms if len(lines) != (self.natom + 2): print("Error: incorrectly formatted xyz file") return self.units = lines[1].rstrip() #second line = Angstroms or Bohr if self.units != "Angstrom" and self.units != "Bohr": print("Error: unspecified units or units we are currently unequipped to handle.") return self.labels = [] for line in lines[2:]: #from the third line to the end self.labels = self.labels + [line[0]] #append the first character self.masses = [masses.get_mass(i) for i in self.labels] #creates a list of the masses self.charges = [masses.get_charge(i) for i in self.labels] #creates a list of the charges fgeoms = [] for line in lines[2:]: #from the third line to the end line = line.split() newline = line[1:] #leave out the atom name, have list of xyz's for i in range(len(newline)): newline[i] = float(newline[i]) #converting to float fgeoms = fgeoms + [newline] #a list of lists of the xyz values self.geoms = np.array(fgeoms) #making an array out of the list of lists
def __init__(self, geom): """ Creates a molecule with a geometry and corresponding units """ lines = geom.strip().split("\n") units = lines[1].lower() natom = int(lines[0]) atoms = [] geom = [] for line in lines[2:]: atom, x, y, z = line.split() atoms.append(atom) geom.append([float(x), float(y), float(z)]) self.units = units self.natom = natom self.atoms = atoms self.geom = np.array(geom) mass = [] charges =[] for atom in atoms: mass.append(float(masses.get_mass(atom))) charges.append(int(masses.get_charge(atom))) #might want to include symbols self.mass = mass self.charges = charges
def plot_pk_mass(data_frame, to_plot=True): """ Plots the pk mass :param data_frame: :param to_plot: :return: """ particles_associations = [['Kminus_P', 'K'], ['proton_P', 'proton']] data_frame['pk_mass'] = get_mass( data_frame=data_frame, particles_associations=particles_associations) if to_plot: df_with_signs = data_frame[np.sign(data_frame['Kminus_ID']) != np.sign( data_frame['proton_ID'])] plt.hist(df_with_signs['pk_mass'], bins=120, range=[1400, 2600]) # peak 1480 to 1555 plt.xlabel('$m_{pK}$') plt.ylabel('occurrences') plt.show() a = data_frame[(data_frame['pk_mass'] > 1480) & (data_frame['pk_mass'] < 1550)] plt.hist(a['pKmu_ENDVERTEX_CHI2'], bins=50) plt.xlabel('pKmu_ENDVERTEX_CHI2') plt.show() # data_frame = data_frame[(data_frame['pk_mass'] < 1480) | (data_frame['pk_mass'] > 1550)] # data_frame = data_frame[(data_frame['pk_mass'] < 1500) | (data_frame['pk_mass'] > 1540)] # data_frame = data_frame[(data_frame['pk_mass'] > 1910) | (data_frame['pk_mass'] < 1850)] return data_frame
def jpsi_swaps(data_frame): """ Look for jpsi swaps :param data_frame: :return: """ particles_duos = [['mu1_P', 'tauMu_P'], ['mu1_P', 'proton_P'], ['mu1_P', 'Kminus_P'], ['tauMu_P', 'proton_P'], ['tauMu_P', 'Kminus_P'], ['proton_P', 'Kminus_P']] for p1, p2 in particles_duos: particles_associations = [[p1, 'mu'], [p2, 'mu']] if ('mu' in p1.lower() and 'mu' in p2.lower()) or ('mu' not in p1.lower() and 'mu' not in p2.lower()): mass_frame = data_frame[np.sign(data_frame[p1[:-2] + '_ID']) != np.sign(data_frame[p2[:-2] + '_ID'])] else: mass_frame = data_frame[np.sign(data_frame[p1[:-2] + '_ID']) == np.sign(data_frame[p2[:-2] + '_ID'])] mass = get_mass(data_frame=mass_frame, particles_associations=particles_associations) plt.hist(mass, bins=100) plt.axvline(masses['J/psi'], c='k') plt.xlabel(p1[:-2] + ' ' + p2[:-2]) plt.xlim(right=4500) plt.show() return data_frame
def __init__(self, geom): """ Creates a molecule with a geometry and corresponding units """ lines = geom.strip().split("\n") units = lines[1].lower() natom = int(lines[0]) atoms = [] geom = [] for line in lines[2:]: atom, x, y, z = line.split() atoms.append(atom) geom.append([float(x), float(y), float(z)]) self.units = units self.natom = natom self.atoms = atoms self.geom = np.array(geom) mass = [] charges = [] for atom in atoms: mass.append(float(masses.get_mass(atom))) charges.append(int( masses.get_charge(atom))) #might want to include symbols self.mass = mass self.charges = charges
def __init__(self, data) : """ data -- contents of an .xyz file as a str """ data = data.split('\n') self.natom = int(data[0]) self.units = data[1] self.labels = [] self.masses = [] self.charges = [] self.geom = [] for atom in data[2:] : atom = atom.split() if len(atom) != 4 : continue # Throw Error? self.labels.append(atom[0]) self.masses.append(m.get_mass(atom[0])) self.charges.append(m.get_charge(atom[0])) self.geom.append(atom[1:]) self.geom = [[float(coord) for coord in atom] for atom in self.geom]
def read(self, geom_str): #Read in the file containing the geometry of the molecule in question #print("\n" + "MOLECULE INFORMATION" + "\n") geom = [] self.labels = [] self.masses = [] self.charges = [] lines = geom_str.strip().splitlines() self.natom = int(lines[0]) #print("Number of atoms: " + str(self.natom) + "\n") #print("Units are currently in: " + self.units + "\n") for line in lines[2:]: atom, x, y, z = line.split() self.labels.append(atom) geom.append([float(x), float(y), float(z)]) self.geom = np.array(geom) #print("Atoms: " + str(self.labels)+ "\n") #Reading in the masses and charges of the atoms from the .xyz file for x in self.labels: self.masses.append(get_mass(x)) self.charges.append(get_charge(x)) y = 0 for x in self.labels: #print("Mass of " + x + " is: " + str(self.masses[y])) #print("Charge of " + x + " is: " + str(self.charges[y])) y += 1 #print("\n") #print("Molecular Geometry in: " + self.units + "\n") #print(self.geom) return self.geom, self.natom, self.labels
def mass_charge(self): sys.path.insert(0, '../../extra-files') import masses as M mass = [float(M.get_mass(self.labels[i])) for i in range(self.natom)] charge = [M.get_charge(self.labels[i]) for i in range(self.natom)] return (mass, charge)
def __init__(self,data): #checking if input string is filename or xyzstring by determining number of lines if data.endswith('.xyz'): with open(data, 'r') as moleculefile: self.moleculelines = moleculefile.readlines() else: self.moleculelines = data.split('\n') #units are supplied on line 2 self.units = self.moleculelines[1].rstrip() #number of atoms is supplied on line 1 self.natom = int((self.moleculelines[0]).rstrip()) #create empty lists of atom labels, masses, charge, and geometry matrix for later population self.labels = [] self.masses = [] self.charges = [] self.geom = np.zeros((self.natom,3)) #loop through atoms and populate information into empty lists for atom in range(self.natom): #+2 because atoms start at line 3 element,x,y,z = self.moleculelines[atom+2].split() self.labels.append(element) self.charges.append(masses.get_charge(element)) self.masses.append(masses.get_mass(element)) self.geom[atom] = [x,y,z]
def __init__(self, TextFile): # Empty arrays defined to be later appended to self.textfile = TextFile labels = [] geom = [] charges = [] mass = [] # open text file, read in the values, and store them as the desired units with open(TextFile, 'r') as my_file: data = my_file.read().replace('\n', ' ') data = data.split() self.natom = int(data[0]) del data[0] self.units = data[0] del data[0] # reading in rest of the data for i in range(self.natom): # Store the first line of the column as a label labels.append(data[4 * i]) # Temporary list defined to store subarray of geom temp = [] # Cycle through the x,y,z coordinates for j in range(3): temp.append(float(data[4 * i + j + 1])) # Append 1x3 subarray to geom array geom.append(temp) self.labels = labels self.geom = np.array(geom) for i in range(self.natom): mass.append(masses.get_mass(str(labels[i]))) charges.append(masses.get_charge(str(labels[i]))) self.charges = charges self.masses = mass
def __init__(self, data): """ data -- contents of an .xyz file as a str """ data = data.split('\n') self.natom = int(data[0]) self.units = data[1] self.labels = [] self.masses = [] self.charges = [] self.geom = [] for atom in data[2:]: atom = atom.split() if len(atom) != 4: continue # Throw Error? self.labels.append(atom[0]) self.masses.append(m.get_mass(atom[0])) self.charges.append(m.get_charge(atom[0])) self.geom.append(atom[1:]) self.geom = [[float(coord) for coord in atom] for atom in self.geom]
def __init__(self,TextFile): # Empty arrays defined to be later appended to self.current = 0 self.textfile = TextFile labels = [] geom = [] charges = [] mass = [] # open text file, read in the values, and store them as the desired units with open(TextFile,'r') as my_file: data = my_file.read().replace('\n',' ') data = data.split() self.natom = int(data[0]) del data[0] self.units = data[0] del data[0] # reading in rest of the data for i in range(self.natom): # Store the first line of the column as a label labels.append(data[4*i]) # Temporary list defined to store subarray of geom temp = [] # Cycle through the x,y,z coordinates for j in range(3): temp.append(float(data[4 * i + j + 1])) # Append 1x3 subarray to geom array geom.append(temp) self.labels = labels self.geom = np.array(geom) for i in range(self.natom): mass.append(masses.get_mass(str(labels[i]))) charges.append(masses.get_charge(str(labels[i]))) self.charges = charges self.masses = mass
def plot_pipimumu_mass(data_frame, to_plot): """ Plots the pikmumu mass where the proton has a pion hypothesis :param data_frame: :param to_plot: :return: """ particles_associations = [['Kminus_P', 'pi'], ['proton_P', 'pi'], ['mu1_P', 'mu'], ['tauMu_P', 'mu']] data_frame['pipimumu_mass'] = get_mass( data_frame=data_frame, particles_associations=particles_associations) particles_associations = [['Kminus_P', 'pi'], ['proton_P', 'pi']] data_frame['pipi_mass'] = get_mass( data_frame=data_frame, particles_associations=particles_associations) data_frame['mumu_mass'] = get_mass( data_frame=data_frame, particles_associations=[['mu1_P', 'mu'], ['tauMu_P', 'mu']]) if to_plot: plt.hist2d(data_frame['pipimumu_mass'], data_frame['pipi_mass'], bins=30, range=[[2000, 7000], [200, 2000]]) plt.xlabel('$m_{\\pi\\pi\\mu\\mu}$') plt.ylabel('$m_{\\pi\\pi}$') plt.show() plt.show() plt.hist(data_frame['pipimumu_mass'], bins=100, range=[2000, 7000]) plt.xlabel('$m_{\\pi\\pi\\mu\\mu}$') plt.ylabel('occurrences') plt.axvline(masses['B'], c='k') plt.show() plt.hist(data_frame['pipi_mass'], bins=100, range=[200, 2000]) plt.xlabel('$m_{\\pi\\pi}$') plt.ylabel('occurrences') plt.axvline(masses['K'], c='k') plt.show() plt.hist(data_frame['mumu_mass'], bins=100, range=[200, 2000]) plt.xlabel('$m_{\\mu\\mu}$') plt.ylabel('occurrences') plt.axvline(masses['K'], c='k') plt.show() data_frame = data_frame[(data_frame['pipimumu_mass'] < masses['B']) | (data_frame['pipimumu_mass'] > masses['B'] + 100)] return data_frame
def pp_mass(data_frame, to_plot): particles_associations = [['Kminus_P', 'proton'], ['proton_P', 'proton']] data_frame['pp_mass'] = get_mass( data_frame=data_frame, particles_associations=particles_associations) if to_plot: plt.hist(data_frame['pp_mass'], bins=100, range=[1800, 3000]) plt.xlabel('$m_{pp}$') plt.ylabel('occurrences') plt.show() return data_frame
def __init__(self,inputString,lengthUnits="Angstrom",angleUnits="Degree"): self.inputString = inputString self.lengthUnits = lengthUnits self.angleUnits = angleUnits self.read(inputString) self.masses = [ float(get_mass(i)) for i in self.atoms ] self.charges = [ int(get_charge(i)) for i in self.atoms ]
def kk_mass(data_frame, to_plot): particles_associations = [['Kminus_P', 'K'], ['proton_P', 'K']] data_frame['kk_mass'] = get_mass( data_frame=data_frame, particles_associations=particles_associations) if to_plot: plt.hist(data_frame['kk_mass'], bins=100, range=[1000, 2500]) plt.xlabel('$m_{KK}$') plt.ylabel('occurrences') plt.show() data_frame = data_frame[data_frame['kk_mass'] > 1220] return data_frame
def plot_kpmumu_mass(data_frame, to_plot): """ Plots the pikmumu mass where the proton has a pion hypothesis :param data_frame: :param to_plot: :return: """ particles_associations = [['Kminus_P', 'proton'], ['proton_P', 'K'], ['mu1_P', 'mu'], ['tauMu_P', 'mu']] data_frame['kpmumu_mass'] = get_mass( data_frame=data_frame, particles_associations=particles_associations) particles_associations = [['Kminus_P', 'proton'], ['proton_P', 'K']] data_frame['kp_mass'] = get_mass( data_frame=data_frame, particles_associations=particles_associations) if to_plot: plt.hist(data_frame['kpmumu_mass'], bins=100, range=[3500, 8000]) plt.hist(data_frame[(data_frame['Lb_M'] > 5620 - 40) & (data_frame['Lb_M'] < 5620 + 40)]['kpmumu_mass'], bins=100, range=[3500, 8000]) plt.axvline(masses['Lb'], c='k') plt.xlabel('$m_{kp\\mu\\mu}$') plt.ylabel('occurrences') plt.show() plt.hist(data_frame[(data_frame['Lb_M'] < 5620 - 40) | (data_frame['Lb_M'] > 5620 + 40)]['kpmumu_mass'], bins=100, range=[3500, 8000]) plt.axvline(masses['Lb'], c='k') plt.xlabel('$m_{kp\\mu\\mu}$') plt.ylabel('occurrences') plt.show() plt.hist2d(data_frame['kpmumu_mass'], data_frame['kp_mass'], bins=50, range=[[3500, 6500], [1450, 3000]]) plt.show() data_frame = data_frame[(data_frame['kpmumu_mass'] < 5620 - 40) | (data_frame['kpmumu_mass'] > 5620 + 40)] return data_frame
def get_stretched_pikmu_mass(data_frame, particles_associations): """ Obtains (here) distribution of the pkmu mass from the pikmu mass :param data_frame: :param particles_associations: :return: """ sum_m = get_mass(data_frame, particles_associations=particles_associations) sum_m = sum_m - 739 # supposed minimum mass of pikmu sum_m = sum_m / (3502 - 739) # supposed to be range covered by pikmu mass sum_m = sum_m * (3843 - 1537) # supposed to be range covered by pkmu mass sum_m = sum_m + 1537 # supposed to be minimum mass of pkmu return sum_m
def __init__(self, geom_str): lines = geom_str.splitlines() # splitting lines of input file self.natom = int(lines[0]) # number of atoms in the input self.units = lines[1] # units of geometry self.labels = [] # atoms in the input file self.mass = [] # mass of each atom self.charge = [] # charge of each atom self.geom = [] # geometry of molecule in xyz coordinates for line in lines[2:]: atom, x, y, z = line.split() self.labels.append(str(atom)) self.mass.append(float(masses.get_mass(atom))) self.charge.append(int(masses.get_charge(atom))) self.geom.append([float(x), float(y), float(z)]) self.geom = np.array(self.geom) # matrix of xyz coordinates
def __init__(self, geom_str): lines=geom_str.splitlines() # splitting lines of input file self.natom = int(lines[0]) # number of atoms in the input self.units = lines[1] # units of geometry self.labels = [] # atoms in the input file self.mass = [] # mass of each atom self.charge = [] # charge of each atom self.geom = [] # geometry of molecule in xyz coordinates for line in lines[2:]: atom,x,y,z = line.split() self.labels.append(str(atom)) self.mass.append(float(masses.get_mass(atom))) self.charge.append(int(masses.get_charge(atom))) self.geom.append([float(x),float(y),float(z)]) self.geom = np.array(self.geom) # matrix of xyz coordinates
def get_stretched_kmu_mass(data_frame, particles_associations): """ Obtains (here) distribution of the kmu mass from the B MC kmu mass :param data_frame: :param particles_associations: :return: """ sum_m = get_mass(data_frame, particles_associations=particles_associations) minimum_kmu_mass = masses['K'] + masses['mu'] maximum_kmu_mass_b = masses['B'] - masses['pi'] - masses['tau'] maximum_kmu_mass_lb = masses['Lb'] - masses['proton'] - masses['tau'] sum_m = sum_m - minimum_kmu_mass sum_m = sum_m / (maximum_kmu_mass_b - minimum_kmu_mass) sum_m = sum_m * (maximum_kmu_mass_lb - minimum_kmu_mass) sum_m = sum_m + minimum_kmu_mass return sum_m
def plot_pmumu_mass(data_frame, to_plot=True): """ :param data_frame: :param to_plot: :return: """ particles_associations = [['proton_P', 'proton'], ['mu1_P', 'mu'], ['tauMu_P', 'mu']] data_frame['pmumu_mass'] = get_mass( data_frame=data_frame, particles_associations=particles_associations) if to_plot: plt.hist(data_frame['pmumu_mass'], bins=100) plt.xlabel('$m_{p\\mu\\mu}$') plt.ylabel('occurrences') plt.show() return data_frame
def get_freqs(mol, hes='../extra-files/hessian.dat'): mol.to_angstrom() # converting geometry to be in angstroms mass = [] # forming a list with 1/sqrt(individual masses) for atom in mol.labels: # for each of the x, y, x coordinates mass += [masses.get_mass(atom)**(-0.5)] * 3 M = np.diag(mass) # putting list in diagonal matrix hessian = np.loadtxt(hes) # reading in hessian file H = M @ hessian @ M # building mass weighted hessian k, q = np.linalg.eigh(H) #diagonalizing mass weighted hessian Q = M @ q #un-mass-weight eigenvectors #determining spatial frequencies in cm^-1 hartreetoJ = 4.3597443e-18 amutokg = 1.6605389e-27 bohrtom = 5.2917721e-11 c = 2.99792458e10 ka = k * hartreetoJ * (1 / amutokg) * (1 / bohrtom)**2 # ka in a.u. va_conv = (1 / (2 * np.pi)) * (1 / c) va = ka * va_conv # va is frequencies in cm^-1 # formatting for output: geometries, frequencies, and normal modes out = '' line_form = '{:2s}' + '{: >15.10f}' * 6 + '\n' for a, k_a in enumerate(ka): if k_a < 0: out += '{}\n{: >7.2f}i cm^-1\n'.format( mol.natom, np.sqrt(np.absolute(k_a)) * va_conv) else: out += '{}\n{: >7.2f} cm^-1\n'.format(mol.natom, np.sqrt(k_a) * va_conv) for i in range(mol.natom): atom = mol.labels[i] x, y, z = mol.geom[i] dx, dy, dz = Q[3 * i:3 * i + 3, a] out += line_form.format(atom, x, y, z, dx, dy, dz) out += '\n' with open('frequencies.xyz', 'w') as f: # writing output to file frequencies.xyz f.write(out)
def plot_pmu_mass(data_frame): """ Plots the pmu mass :param data_frame: :return: """ particles_associations = [['proton_P', 'proton'], ['mu1_P', 'mu']] data_frame['pmu'] = get_mass(data_frame=data_frame, particles_associations=particles_associations) df_to_plot = data_frame[np.sign(data_frame['proton_ID']) == np.sign( data_frame['mu1_ID'])] plt.hist(df_to_plot['pmu'], bins=100, range=[1400, 3700]) plt.xlim(right=3700) plt.xlabel('$m_{p\\mu}$') plt.ylabel('occurrences') plt.show() return data_frame
def __init__(self, xyzstring, units="angstrom"): labels = [] geom = [] try: lines = xyzstring.strip().splitlines() natom = int(lines[0]) for line in lines[2:]: l, x, y, z = line.split() labels.append(l.upper()) geom.append([float(x), float(y), float(z)]) except: raise Exception("Invalid .xyz string\n'''\n{:s}\n'''\npassed to Molecule constructor.".format(xyzstring)) self.units = units self.natom = natom self.labels = labels self.masses = [get_mass(label) for label in labels] self.charges = [get_charge(label) for label in labels] self.geom = np.array(geom)
def get_freqs(mol, hes = '../extra-files/hessian.dat'): mol.to_angstrom() # converting geometry to be in angstroms mass = [] # forming a list with 1/sqrt(individual masses) for atom in mol.labels: # for each of the x, y, x coordinates mass += [masses.get_mass(atom)**(-0.5)]*3 M = np.diag(mass) # putting list in diagonal matrix hessian = np.loadtxt(hes) # reading in hessian file H = M @ hessian @ M # building mass weighted hessian k, q = np.linalg.eigh(H) #diagonalizing mass weighted hessian Q = M @ q #un-mass-weight eigenvectors #determining spatial frequencies in cm^-1 hartreetoJ = 4.3597443e-18 amutokg = 1.6605389e-27 bohrtom = 5.2917721e-11 c = 2.99792458e10 ka = k * hartreetoJ * (1/amutokg) * (1/bohrtom)**2 # ka in a.u. va_conv = (1/(2 * np.pi)) * (1/c) va = ka * va_conv # va is frequencies in cm^-1 # formatting for output: geometries, frequencies, and normal modes out = '' line_form = '{:2s}' + '{: >15.10f}'*6 + '\n' for a , k_a in enumerate(ka): if k_a < 0: out += '{}\n{: >7.2f}i cm^-1\n'.format(mol.natom, np.sqrt(np.absolute(k_a))*va_conv) else: out += '{}\n{: >7.2f} cm^-1\n'.format(mol.natom, np.sqrt(k_a)*va_conv) for i in range(mol.natom): atom = mol.labels[i] x, y, z = mol.geom[i] dx, dy, dz = Q[3*i: 3*i + 3, a] out += line_form.format(atom, x, y, z, dx, dy, dz) out += '\n' with open('frequencies.xyz', 'w') as f: # writing output to file frequencies.xyz f.write(out)
def __init__(self, geom_path): f = open(geom_path) lines = f.readlines() f.close() self.natom = int(lines[0]) self.units = lines[1] # initialize stuff self.labels = [] self.charges = [] self.masses = [] self.xyz = [] # get geoms for line in lines[2:]: atom, x, y, z = line.split() self.labels.append(atom) self.charges.append(get_charge(atom)) self.masses.append(get_mass(atom)) self.xyz.append((float(x), float(y), float(z))) self.geom = np.array(self.xyz) # make numpy array
def parse_molecule(self, mole_str): """ Parses data from .xyz file to change class attributes :param mole_str: string (typically .xyz file) describing a molecule """ lines = mole_str.strip().split("\n") self.natom = int(lines[0]) if lines[1].lower() == "angstrom": self.units = "angstrom" elif lines[1].lower() == "bohr": self.units = "bohr" self.labels = [i.strip().split(" ")[0].strip() for i in lines[2:]] self.masses = [m.get_mass( l ) for l in self.labels ] self.charges = [m.get_charge( l ) for l in self.labels ] tempArray = [i.split(" ")[1:4] for i in lines[2:]] for a in range(len(tempArray)): for b in range(len(tempArray[a])): tempArray[a][b] = float(tempArray[a][b] ) self.geom = np.array(tempArray)
def remove_high_pkmu_mass(data_frame): """ Removes pkmu masses high enough so that no tau can be present in the decay This cut is only applied on the mass of p, K and mu1, as we do nto expect mu1 to come from a tau :param data_frame: data frame to cut on :return: """ data_frame['pkmu'] = get_mass( data_frame, particles_associations=[['Kminus_P', 'K'], ['proton_P', 'proton'], ['mu1_P', 'mu']]) to_drop_1 = data_frame[ (np.sign(data_frame['Kminus_ID']) == np.sign(data_frame['mu1_ID'])) & (data_frame['pkmu'] > masses['Lb'] - masses['tau'])] data_frame = data_frame.drop(list(to_drop_1.index)) # to_drop_2 = data_frame[ # (np.sign(data_frame['Kminus_ID']) == np.sign(data_frame['tauMu_ID'])) & (data_frame['pktauMu'] > 3839)] # data_frame = data_frame.drop(list(to_drop_2.index)) return data_frame
def __init__(self, xyz): self.units = "Angstrom" self.labels = [] self.masses = [] self.charges = [] xyz_lines = filename_to_lines(xyz) # Get the number of atoms. natom = get_elt_0(xyz_lines, "Line 1", "file {}".format(xyz)) self.natom = validate_int(natom, "Line 1") # Validate the file length. validate_array_length(self.natom + 2, xyz_lines, "XYZ input", "lines") geom = numpy.empty([0, 3]) for i, line in enumerate(xyz_lines[2:]): # Ensure a coordinate line is valid before processing it. atom, matr_row = validate_coord_line(line, i + 3) geom = numpy.vstack((geom, matr_row)) self.labels.append(atom) self.charges.append(masses.get_charge(atom)) self.masses.append(masses.get_mass(atom)) self.geom = geom
def write_dat(self,outfile=None): if outfile is None: of = sys.stdout else: of = open(outfile,'w') of.write(self.comment+'\n') of.write('{0} atoms\n\n'.format(self.natoms)) of.write('{0} atom types\n\n'.format(len(self.atomtypes))) of.write('{0} {1} xlo xhi\n'.format(-self.lx/2,self.lx/2)) of.write('{0} {1} ylo yhi\n'.format(-self.ly/2,self.ly/2)) of.write('{0} {1} zlo zhi\n\n'.format(-self.lz/2,self.lz/2)) of.write('Masses\n\n') atomtypes = list(self.atomtypes) atomtypes.sort() atomtypes.reverse() for i,z in enumerate(atomtypes): of.write('{0} {1}\n'.format(i+1,round(masses.get_mass(z),2))) of.write('\n') of.write('Atoms\n\n') for i,atom in enumerate(self.atoms): of.write('{0} {1} {2} {3} {4}\n'.format(atom.id+1, atomtypes.index(atom.z)+1, atom.coord[0], atom.coord[1], atom.coord[2]))
def __init__(self, zmatrix): labels = [] zmat_keys = [] zmat = {} for atom1, line in enumerate(zmatrix.strip().splitlines()): items = line.split() labels.append( items.pop(0) ) key = (atom1,) for atom2, value in zip(items[0::2], items[1::2]): key += (int(atom2) - 1,) # -1 because we're 0-indexing zmat_keys.append(key) value = float(value) if len(key) < 3 else float(value) * 2 * np.pi / 360. # convert to radians if it's an angle zmat.update({key: float(value)}) self.natoms = len(labels) self.nintcos = len(zmat_keys) self.labels = labels self.masses = [get_mass(label) for label in labels] self.zmat_keys = zmat_keys self.zmat = zmat self.geom = np.zeros((self.natoms, 3)) self.fill_geom_from_zmat()
def __init__(self, xyz_file, units="Angstrom"): self.units = units self.read(xyz_file) self.masses = [ float(get_mass(i)) for i in self.atoms ] self.charges = [ int(get_charge(i)) for i in self.atoms ]
##### Read in the molecule f = open("../extra-files/molecule.xyz").readlines() mol = Molecule(f,"Bohr") mol.angs() N = mol.__len__() ##### Read in the Hessian g = open("../extra-files/hessian.dat","r") H0 = np.matrix([i.split() for i in g.readlines()],float) ##### Construct M^{-1/2} (diagonal matrix) m = [] for i in mol.atoms: m += [1/(masses.get_mass(i))**0.5]*3 M = np.diag(m) ##### Mass-weight the Hessian mH = M*H0*M ##### Diagonalize Hessian e, l = la.eigh(mH) ##### Eigenvectors --> vibrational modes Q = np.matrix(M)*np.matrix(l)
sys.path.insert(0, '../../0/jevandezande') from masses import get_mass from molecule import Molecule # Create a molecule mol = Molecule(open('../extra-files/molecule.xyz').read(), 'Bohr') mol.to_angstrom() # Read the Hessian H = np.genfromtxt('../extra-files/hessian.dat') # Mass weight Hessian # Build W = M^{-1/2} weights = [] for atom in mol.atoms: w = 1/np.sqrt(get_mass(atom)) weights += [w, w, w] W = np.diag(weights) # \Tilde H = M^{-1/2} H M^{-1/2} Ht = W @ H @ W # Diagonalize the Hessian # \Tilde H = L \Lambda L^T k, L = np.linalg.eigh(Ht) # \lambda_a = \omega^2 hartree2J = 4.3597443e-18 amu2kg = 1.6605389e-27 bohr2m = 5.2917721e-11 c = 29979245800.0 # speed of light in cm/s
mol = Molecule(open("../extra-files/molecule.xyz").read()) mol.bohr_to_ang() #read Hessian Values hessian_values = open('../extra-files/hessian.dat').readlines() #collect hessain values into matrix H = [] A = len(mol) #this is redefined to give number of atoms for row in hessian_values: for x in row.split(): H.append(x) hessian = np.matrix(H, float) hessian = np.reshape(hessian,(3*A, 3*A)) m = [] M = [] for atom in mol.atoms: m.append(masses.get_mass(atom)) m.append(masses.get_mass(atom)) m.append(masses.get_mass(atom)) for mass in m: M.append(mass**-0.5) M = np.diag(M) mass_weighted_hess = M*hessian*M eigens = np.linalg.eigh(mass_weighted_hess)
def __init__(self, geom, units = "Angstrom"): self.read(geom) self.units = units self.charge = [get_charge(atom) for atom in self.atoms] self.mass = [get_mass(atom) for atom in self.atoms]
def __init__(self,geom_str,units = "Angstrom"): self.read(geom_str) self.units = units self.charge = [get_charge(i) for i in self.label] self.mass = [get_mass(i) for i in self.label]
mol = Molecule(open('../../extra-files/molecule.xyz').read()) # Build mass-weighted hessian H = [] for line in lines: H.append(list(map(float, line.split()))) H = np.matrix(H) M = [] for atom in mol.atoms: M.append(1/np.sqrt(get_mass(atom))) M.append(1/np.sqrt(get_mass(atom))) M.append(1/np.sqrt(get_mass(atom))) M = np.diag(M) mwH = M * H * M # Compute eigenvalues and eigenvectors e, v = np.linalg.eigh(mwH) # un-mass-weight to normal coordinates Q = np.array(np.matrix(M) * np.matrix(v))