Demo entry 6308344

Tryout

   

Submitted by anonymous on Oct 23, 2016 at 01:01
Language: Python. Code size: 1.9 kB.

#!/usr/bin/env python
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.pyplot as colors
from textwrap import wrap
import os
Textfiles = []
for file in os.listdir("/Users/andreasluttens/Desktop/Conformational Analysis/Basis_sets"):
    if file.endswith(".txt"):
        Textfiles.append(file)

radius = np.linspace(0.0,6.0,num = 1000000)
elements = ['H', 'C', 'N', 'O']
colors = ['b','cyan','gold','cornflowerblue']

def information(text):
    atoms = dict()
    current_atom = ''
    with open(text, 'r') as f:
        for line in f:
            if line[0] not in atoms and line[0] in elements:
                current_atom = line[0]
                couple = {line[0]:[]}
                atoms.update(couple)
            if line[0] ==' ':
                atoms[current_atom].append(map(float,line.split()))
    return atoms

def gaussian(alpha,radius):
    single_gaus = (2.0*alpha/np.pi)**(3.0/4.0)*np.exp(-1.0*alpha*radius**2.0)
    return single_gaus

def combination(text, radius):
    database = information(text)
    combined = dict()
    for atom in database:
        combo_gaus = 0
        for data_couple in database[atom]:
            combo_gaus += data_couple[1]*gaussian(data_couple[0],radius)
        combined.update({atom:combo_gaus})
    return combined
        
def graphical(Textfiles, radius):
    diff_sets = list()
    for set_file in Textfiles:
        name_set = set_file[:set_file.find('.')]
        diff_sets.append((name_set,combination(set_file,radius)))
    for atom in elements:
        plt.plot()
        plt.ylabel(u'\u03A8')
        plt.xlabel('r('u'\u212B'')')
        plt.title('Comparison of basis sets for the '+atom+' atom')
        for basis_set in diff_sets:
            plt.plot(radius,basis_set[1][atom],colors[diff_sets.index(basis_set)],
		label = basis_set[0] +' basis set', linewidth = 2)
        plt.legend(loc=1)
        plt.show()
    return True

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).