Advanced Lectures on Applied Chemistry
Computer Science for Chemistry
(化学のためのコンピュータサイエンス)
Masaru Mitsushio
Computer science
Computer science is a field of research on information and
theoretical calculation which is carried out on the computer.
Internet, distributed computing (e. g. Folding@Home), and
Human Genome Project are results of the computer science.
In the modern chemistry, the support of the computer is indispensable.
I will explain a part of the computer science
(including computational science and computational chemistry).
Key parsons and key words of the computer science
【Augusta Ada King】
・Augusta Ada King called as the first programmer of the world.
・Her portrait has been used in the hologram sticker of the Microsoft corporation.
(But, I Couldn't find her portrait on the discs of the software purchased by
Microsoft corporation.)
・Etymology of the programming language "Ada".
【John von Neumann】
・Sometime, he calls the Father of the computer.
・He and his coworkers developed the
stored-program type computer, which is called
Neumann type computer.
【Grace Murray Hopper】
・Her nickname was amazing Grace.
・The Brigadier General(准将) of US NAVY.
・One of the first programmer of the computer "Harvard Mark I".
・She developed the Programming language "COBOL".
References
Wikipedia:エイダ・ラブレス、ジョン・フォン・ノイマン、Harvard Mark I、
バグ、ENIAC http://www.wizforest.com/OldGood/eniac/
【Analytical engine】
・Analytical engine was projected by Charles Babbage.
The analytical engine in this photograph is constructed
according to his plan.
・Power source in his project was steam.
・Ada made the program for this analytical engine in her book.
Relay #70 Panel F
(moth) in relay
First actual case of bug being found
Debug report written by Grace Murray Hopper
(For the computer "Harvard Mark II")
"ENIAC, it is called the first computer of the world."
(Electronic Numerical Integrator and Computer)
・It consisted of tens of thousands of vacuum tubes and relays.
・It carried out the calculation with decimal system
(not binary system).
Practical samples
Chemical reactions can be expected
by the computer science
without experiments.
Heat of Formation was calculated
with software for a molecular dynamics.
Practical samples
Pi calculation with the Monte Carlo method
R
2R
We can calculate the "Pi" with this square and circle.
Think how we can calculate with this figure.
Monte Carlo Method:
General name of the method for simulation and numerical calculation
by using a random number
In this figure, we can mark random dots in this square.
Practical samples
Pi calculation with the Monte Carlo method
R: Radius of the circle
R
Area of the circle : Ac = πR2
Area of the square : As = 4R2
2R
If you mark with random dots in this square,
the ratio of the number of the dot in and out of the circle is equal to gray and white ratio.
Nin : Nout = πR2 : (4R2 - πR2)
where,
Nin : Number of the dot in the circle
Nout : Number of the dot out of the circle
Then, this equation is transformed into as follows.
4 Nin
π=
Nin + Nout
Reference
松田 聡, 産業技術総合研究所 ダイバーシティ推進室 「モンテカルロ法のお話」
https://unit.aist.go.jp/diversity/ja/jst/teens/montecarlo.htm
(有)ゴッドフット企画, Excelで操る!モンテカルロシミュレーションによる円周率(π)計算
http://homepage1.nifty.com/gfk/monte_pai.htm
Algorithm
How do we judge whether it is located in the circle?
R
2R
Random dot
x
y
r
r = x2+y2 ≦ R : located in the circle
R
How do we make a random dot in the square?
make a random value within ±R
=COUNTIF(G13:G76,"○")
=COUNTIF(G13:G76,"")
=4*E5/(E5+E6)
=SQRT(D13^2+E13^2)
=RAND()*2*$E$4-$E$4
Copy the formula
with an autofill function ↓
=IF(F13<=$E$4, "○","")
Excel calculation
Private Sub CommandButton1_Click()
'If E4 and E5 cell (R and Num. of dot) is empty, input 10 and 10000, respectively.
If Range("E4") = "" Then Range("E4") = 10
If Range("E5") = "" Then Range("E5") = 10000
'mark
Dim
Dim
Dim
Dim
dots with random x and y
x As Double, y As Double
Nin As Long, Nout As Long
R As Double, NoD As Long
i As Long
'coordinate of the random dot
'counters for Nin and Nout
'radius of the circle and Number of dot
'counter for For-Next construction
Nin = 0
Nout = 0
R = Range("E4")
NoD = Range("E5")
For i = 1 To NoD
'make a dot in the square
x = Rnd(1) * 2 * R - R
y = Rnd(1) * 2 * R - R
'judge whether is the dot in the circle?
If Sqr(x ^ 2 + y ^ 2) <= R Then Nin = Nin + 1
If Sqr(x ^ 2 + y ^ 2) > R Then Nout = Nout + 1
Next
'display the
Range("D10")
Range("E10")
Range("D11")
Range("E11")
Range("D12")
Range("E12")
End Sub
results
= "Nin"
= Nin
= "Nout"
= Nout
= "π="
= 4 * Nin / (Nin + Nout)
Important point for calculation with the spreadsheet software
(e. g. Microsoft Excel)
Many of spreadsheet software are weak in calculations of decimal fractions.
Why?
The computer uses binary or hexadecimal number.
The binary (or hexadecimal) number has no concept of the decimal fraction.
Calculation with the decimal fraction needs a lot of time for a computer.
So, the computer treats the decimal fraction as a floating point.
fraction
floating point
0.0000123 → 1.23 ×10-5
And then, floating point of decimal number is converted into the binary number.
Let's calculate with the decimal fractions on Excel.
=B1-B2
A part of the screen shot of the Excel 2013
=B1-B2
The answer is displayed up to the 20th decimal place.
=B1-B2
True
False
=IF(B3=0.01,"○","×")
Judgement miss of the Excel
If the calculation is correct,
in the case of 0.01 in the B3 cell, "○" is displayed in the B4 cell.
When the decimal fractions converted into the binary number,
it is yielding repeating binary fractions.
Decimal fractions recognized in the Excel
Reference 日経PC21『「第1回 小数計算で発生する「誤差」』
http://pc.nikkeibp.co.jp/pc21/special/gosa/eg1.shtml
In simple calculation, the Excel correct these errors automatically,
but in complex calculations, the results will be influenced by them.
Exercise 1 How do we calculate correctly in the Excel?
Answer an algorithm
Answer 1 Round off the calculated result to two decimal place
Significant figures of the given data (0.41 and 0.40) has up to two decimal place.
Third decimal place
0.0099999999・・・・・
Two decimal place
Answer 2 Calculate the given number as an integer by multiplying 100
(0.41×100 - 0.40×100) ÷ 100
(0.41- 0.40) ×100 ÷ 100 is wrong!
Exercise 2 How shall we describe in the Excel?
Answer 1 Round off the calculated result to two decimal place
=INT((B1-B2)*100+0.5)/100
INT() : Truncate the decimal point
Answer 2 Calculate the given number as an integer by multiplying 100
=(B1*100-B2*100)/100
=(B1-B2)*100/100
Sample case
1
0.9
0.8
反射率
0.7
This is a curve fitting program
with multi layer Fresnel's formula
0.6
0.5
0.4
理論曲線
0.3
測定結果
0.2
0.1
0
64
66
68
70
72
入射角 / 度
74
76
78
80
A part of the program
・
・
'最大値、最小値の計算
Dim emr As Double
Dim sp As Double, ep As Double, tpp As Double, stp As Double
Dim fp As Integer, pso As Double
'最大値の探索
c = c + 1
Sheet1.Cells(c, ag - 1) = "最大値"
sp = Int(Sheet1.Cells(c - 1, ag) * 10) / 10 '臨界角から探索開始
Sheet1.Cells(c, ag) = sp
Call cal(c)
If OptionButton6 = True Then 'フレネル理論式から最大値を算出
For i = 1 To 6
stp = (-1) ^ (i - 1) * 10 ^ -i
fp = 0
Do
Round off the calculated
ep = Sheet1.Cells(c, ag + 1)
sp = sp + stp
'演算時に入るゴミを消去
sp = Int(sp * 10 ^ i + 0.5) / 10 ^ i
result to "i" decimal place
'角度をセルに出力し、反射率を計算させ、ピーク位置を過ぎたかどうかをチェック
Sheet1.Cells(c, ag) = sp
If ep > Sheet1.Cells(c, ag + 1) Then fp = 1 'ピーク位置を過ぎたのでステップ方向反転フラグを立てる
Loop While fp = 0
Next
Else '実験条件で与えられた角度範囲から最大値を算出
・
・
Report
In your research, how can you take advantage of the spreadsheet software?
Describe specifically about 200 characters in Japanese.
あなたの研究において、表計算ソフトはどのように利用できますか?
日本語200字程度で具体的に記述してください。
× 多くのデータを一度に解析して研究の効率を上げたい
○ 1回の実験で常に5つの数値が組になって得られるので、
数回の実験におけるばらつきを比較して実験の精度を評価したい
Submit the report by E-mail to [email protected]
© Copyright 2026 Paperzz