Exemplo n.º 1
0
def vald2numpy(fname, output=None):
    """Converts the VALD output to a numpy array with only the name,
    wavelength, excitation potential, and log gf
    """

    try:
        from periodic.table import element
    except ImportError:
        raise ImportError('Could not import periodic\nInstall with: pip install periodic')

    output = output.replace('.moog', '.npy')

    with open(fname, 'r') as lines:
        newFile = ''
        for line in lines:
            if line.startswith('#') or line.startswith('*'):
                pass
            else:
                newFile += line
    with open(fname, 'w') as f:
        f.write(newFile)

    f = np.loadtxt(fname,
                   dtype={'names': ('elements', 'w', 'excit', 'loggf'),
                          'formats': ('S4', 'f4', 'f4', 'f4')},
                   comments='#', delimiter=',', usecols=(0, 1, 2, 3))

    mol1 = ['CH', 'OH', 'C2', 'CN', 'CO']
    mol2 = ['106', '108', '606', '607', '608']
    mol3 = [3.47, 4.395, 6.25, 7.5, 11.09]
    mol = dict(zip(mol1, [m for m in zip(mol2, mol3)]))

    numpy_out = 'Wavelength\tEle\tExcit\tloggf\t\tD0\n'
    for e, w, ex, l in zip(f['elements'], f['w'], f['excit'], f['loggf']):
        w = str(round(w, 3)).ljust(9, '0')
        iso = e[-1]
        e = e[:-1].strip(' ')
        if e in mol.keys():
            ele_moog = '{}.{}'.format(mol[e][0], str(int(iso) - 1))
            l = str(l).ljust(6, '0')
            z = '\t'.join([w, ele_moog, str(ex), l, str(mol[e][1])]) + '\n'
        else:
            try:
                t = element(e)
                ele_moog = str(t.atomic) + '.' + str(int(iso) - 1)
                l = str(l).ljust(6, '0')
                z = '\t'.join([w, ele_moog, str(ex), l]) + '\n'
            except AttributeError:
                raise AttributeError('The following element does not exist in the dictionary yet: {}'.format(e))

        numpy_out += z

    with open(output, 'w') as f:
        f.write(numpy_out)
    print('Output file: {}'.format(output))
 def energy_levels(self):
     print("Calculating energy levels of atom with (Z > 1)")
     n = int(input("Energy level > "))
     atom_name = input("Name of the atom > ")
     atom = element(atom_name)
     En = -13.60 * (atom.atomic**2) / (n * n)
     print(atom.name, " Energy of state number", n, "is E =", En, " eV")
     store = input("Store this energy instance? (y/n) ")
     if store == 'y':
         self.A_En.append(self.A_En)
         print("Instance stored as number ", len(self.A_En))
     return En
 def transition_wavelength(self):
     print(
         "Wavelength of transition from state ni to nf of non-Hydrogen atom"
     )
     atom_name = input("Name of the atom > ")
     atom = element(atom_name)
     ni = int(input("Transitioning from energy state > "))
     nf = int(input("To energy state > "))
     dE = -13.60 * (atom.atomic**2) * ((1 / ni**2) - (1 / nf**2))
     l = self.h * self.c / dE
     print("Transition wavelength l =", l)
     store = input("Store this wavelength instance? (y/n) ")
     if store == 'Y':
         self.A_wavelength.append(l)
         print("Instance stored as number ", len(self.A_wavelength))
     return l
 def transition_energy(self):
     print(
         "Energy of the transition from state ni to nf of non-hydrogen atom"
     )
     atom_name = input("Name of the atom > ")
     atom = element(atom_name)
     ni = int(input("Transitioning from energy state > "))
     nf = int(input("To energy state > "))
     dE = -13.60 * (atom.atomic**2) * ((1 / ni**2) - (1 / nf**2))
     if dE > 0:
         dE_str = "Absorbed"
     elif dE < 0:
         dE_str = "Given off"
     print("Transition energy dE = ", dE, " eV ", dE_str)
     store = input("Store this energy instance? (y/n) ")
     if store == 'y':
         self.A_dE.append(dE)
         print("Instance stored as number ", len(self.A_dE))
     return dE
Exemplo n.º 5
0
ofile.write('!  %s  EMSL  Basis Set Exchange Library   %s\n' % (basis,today) )
ofile.write('! Elements                             References\n')
ofile.write('! --------                             ----------\n')
ofile.write('! H He B C N O F Ne Al Si P S Cl Ar Ga Ge As Se Br Kr: F. Weigend, A. Kohn, C. Hattig, Efficient use of the correlation consistent basis sets in resolution of the identity MP2 calculations, The Journal of Chemical Physics 116, 3175 (2002).\n')
ofile.write('! Li Be Na Mg: Christof Haettig, Optimization of auxiliary basis sets for RI-MP2 and RI-CC2 calculations: Core-valence and quintuple-? basis sets for H to Ar and QZVPP basis sets for Li to Kr, Physical Chemistry Chemical Physics 7, 59 (2005).\n')
ofile.write('!\n')
ofile.write('\n')
ofile.write('\n')
ofile.write('\n')
ofile.write('\n')
ofile.write('! Basis = %s\n' % (basis))

orbnames = ['s','p','d','f','g','h','i']
for n in range(natoms):
    string = element('%s' % (atoms[0][n]))
    atomname = (string.name).upper()
    data = atoms[1][n]
    b = re.findall('\d+\w',data[1:-1])
    configuration = ','.join(b)
    ofile.write('! %s       (%s)\n' % (atomname,configuration))
    ofile.write('! %s       (%s)\n' % (atomname,configuration))
    for i in range(7):
       if counter[n][i] > 0:
	  ofile.write('! %s functions\n' % (orbnames[i]))
          ofile.write('H    %s    %s\n' % (counter[n][i],counter[n][i]))
	  a = np.identity(counter[n][i])
	  for j in range(counter[n][i]):
	     ofile.write('      %s' % (orbs[n][i][j]))
	     for k in range(counter[n][i]):
	        ofile.write('      %.6f' % (a[j][k]))
Exemplo n.º 6
0
from periodic.table import element
import sys
from pprint import pprint

def sci_round(num):
    return round(num, 3)

if __name__ == "__main__":
    
    # Create a dict of periodic.table.element to the amount
    elements = {}
    key = None
    for i in range(1, len(sys.argv)):
        arg = sys.argv[i]
        if key == None:
            key = element(arg)
            continue
        elements[key] = arg
        key = None

    total_mass = 0
    element_masses = {}
    for (el, count) in elements.items():
        mass = el.mass * float(count)
        element_masses[el] = mass
        total_mass += mass

    print("Total mass: ", sci_round(total_mass))

    for (el, mass) in element_masses.items():
        print(el.name + ":", sci_round((mass / total_mass) * 100), "percent", "with a mass of", sci_round(mass))
Exemplo n.º 7
0
from PIL import ImageFont
from PIL import Image
from PIL import ImageDraw
from periodic.table import element
#elements= [H , He , Li , Be , B , C , N , O , F , Ne , Na , Mg , Al , Si , P , S , Cl , Ar , K , Ca , Sc , Ti , V , Cr , Mn , Fe , Co , Ni , Cu , Zn , Ga , Ge , As , Se , Br , Kr , Rb , Sr , Y , Zr , Nb , Mo , Tc , Ru , Rh , Pd , Ag , Cd , In , Sn , Sb , Te , I , Xe , Cs , Ba , La , Ce , Pr , Nd , Pm , Sm , Eu , Gd , Tb , Dy , Ho , Er , Tm , Yb , Lu , Hf , Ta , W , Re , Os , Ir , Pt , Au , Hg , Tl , Pb , Bi , Po , At , Rn , Fr , Ra , Ac , Th , Pa , U , Np , Pu , Am , Cm , Bk , Cf , Es , Fm , Md , No , Lr , Rf , Db , Sg , Bh , Hs , Mt , Ds , Rg , Cn , Uut , Uuq , Uup , Uuh , Uus , Uuo]
atomicrad=[37, 32, 134, 90, 82, 77, 75, 73, 71, 69, 154, 130, 118, 111, 106, 102, 99, 97, 196, 174, 144, 136, 125, 127, 139, 125, 126, 121, 138, 131, 126, 122, 119, 116, 114, 110, 211, 192, 162, 148, 137, 145, 156, 126, 135, 131, 153, 148, 144, 141, 138, 135, 133, 130, 225, 198, 169, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0160, 150, 138, 146, 159, 128, 137, 128, 144, 149, 148, 147, 146, 0, 0, 145, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

font = ImageFont.truetype("sans-serif.ttf", 96)
bigfont = ImageFont.truetype("sans-serif.ttf", 192)

for an in range(1,117):
    el = element(an).symbol
    ar = atomicrad[an]
    print an, el, ar
    
    if(ar == 0):
        img=Image.open("radioactive.png")
    else:
        img=Image.new("RGBA", (480,480),"white")
    draw = ImageDraw.Draw(img)
    draw.ellipse((240-ar,240-ar,240+ar,240+ar), fill = (255,255-ar,255-ar))
    
    w, h = draw.textsize(el, font=bigfont)
    draw.text((240-(w/2),96),str(an),"black",font=font)
    draw.text((240-(w/2),192),el,"black",font=bigfont)
    
    img.save(str(an)+"_"+el+".png")