def bondlengths(Ea, dE): """Calculate bond lengths and write to bondlengths.csv file""" B = [] E0 = [] csv = open('bondlengths.csv', 'w') for formula, energies in dE: bref = diatomic[formula][1] b = np.linspace(0.96 * bref, 1.04 * bref, 5) e = np.polyfit(b, energies, 3) if not formula in Ea: continue ea, eavasp = Ea[formula] dedb = np.polyder(e, 1) b0 = np.roots(dedb)[1] assert abs(b0 - bref) < 0.1 b = np.linspace(0.96 * bref, 1.04 * bref, 20) e = np.polyval(e, b) - ea if formula == 'O2': plt.plot(b, e, '-', color='0.7', label='GPAW') else: plt.plot(b, e, '-', color='0.7', label='_nolegend_') name = latex(data[formula]['name']) plt.text(b[0], e[0] + 0.2, name) B.append(bref) E0.append(-eavasp) csv.write('`%s`, %.3f, %.3f, %+.3f\n' % (name[1:-1], b0, bref, b0 - bref)) plt.plot(B, E0, 'g.', label='reference') plt.legend(loc='lower right') plt.xlabel('Bond length $\mathrm{\AA}$') plt.ylabel('Energy [eV]') plt.savefig('bondlengths.png')
def atomization_energies(E): """Write given atomization energies to file atomization_energies.csv.""" Ea = {} fd = open('atomization_energies.csv', 'w') for formula in sorted(molecules): ea = -E[formula] for a in string2symbols(data[formula]['symbols']): ea += E[a] eavasp = atomization_vasp[formula][1] * kcal / mol Ea[formula] = (ea, eavasp) name = latex(data[formula]['name']) fd.write('`%s`, %.3f, %.3f, %+.3f\n' % (name[1:-1], ea, eavasp, ea - eavasp)) return Ea
}[v] label += l + ' ' + str(round(value[n], 3)) + '\n' pylab.annotate( label, xy=(n + 0.0, 0.0), xytext=errorslocation(n, n1), arrowprops=None, horizontalalignment='left', verticalalignment='center', fontsize=ann_fontsize, ) # plot compounds with largest errors for n, l in enumerate(largest): for n1, (c, e) in enumerate(l): name = latex(c) + '\n' # matplotlib.pyparsing.ParseFatalException: Expected end of math '$' # $\rm{SiH}2_\rm{s}3\rm{B}1\rm{d}$ (at char 0), (line:1, col:1) name = name.replace('\\rm', '') label = name + ' ' + str(round(e, 2)) pylab.annotate( label, xy=(n + 0.05, e), xytext=formulaslocation(n, n1), arrowprops=dict(width=0.05, headwidth=5.0, facecolor='black', shrink=1.00), horizontalalignment='left', verticalalignment='center', fontsize=ann_fontsize,
value = {"average": average, "absaverage": absaverage, "std": std}[v] label += l + " " + str(round(value[n], 3)) + "\n" pylab.annotate( label, xy=(n + 0.0, 0.0), xytext=errorslocation(n, n1), arrowprops=None, horizontalalignment="left", verticalalignment="center", fontsize=ann_fontsize, ) # plot compounds with largest errors for n, l in enumerate(largest): for n1, (c, e) in enumerate(l): name = latex(c) + "\n" # matplotlib.pyparsing.ParseFatalException: Expected end of math '$' # $\rm{SiH}2_\rm{s}3\rm{B}1\rm{d}$ (at char 0), (line:1, col:1) name = name.replace("\\rm", "") label = name + " " + str(round(e, 2)) pylab.annotate( label, xy=(n + 0.05, e), xytext=formulaslocation(n, n1), arrowprops=dict(width=0.05, headwidth=5.0, facecolor="black", shrink=1.00), horizontalalignment="left", verticalalignment="center", fontsize=ann_fontsize, ) # pylab.show() plot_save(".", tag + "_ea_vs")
'absaverage': absaverage, 'std': std, }[v] label += l + ' ' + str(round(value[n], 3)) + '\n' pylab.annotate(label, xy=(n + 0.0, 0.0), xytext=errorslocation(n, n1), arrowprops=None, horizontalalignment='left', verticalalignment='center', fontsize=ann_fontsize, ) # plot compounds with largest errors for n, l in enumerate(largest): for n1, (c, e) in enumerate(l): name = latex(c) + '\n' # matplotlib.pyparsing.ParseFatalException: Expected end of math '$' # $\rm{SiH}2_\rm{s}3\rm{B}1\rm{d}$ (at char 0), (line:1, col:1) name = name.replace('\\rm', '') label = name + ' ' + str(round(e, 2)) pylab.annotate(label, xy=(n + 0.05, e), xytext=formulaslocation(n, n1), arrowprops=dict(width=0.05, headwidth=5.0, facecolor='black', shrink=1.00), horizontalalignment='left', verticalalignment='center', fontsize=ann_fontsize, ) #pylab.show() plot_save(".", tag + '_ea_vs') #pylab.close(1)