In [77]:
from xmlrpclib import ServerProxy
from IPython.display import Image
import os, sys
import scipy as sp
from scipy import constants
from scipy.constants import codata
import numpy as np
In [78]:
%%bash
export PATH=${PATH}:/home/preps/golovin/progs/bin
export MOPAC_LICENSE=/home/preps/golovin/progs/bin
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/home/preps/golovin/progs/lib
In [79]:
cd /home/students/y12/rita501/term8/pr2
In [104]:
%%bash
echo "c1cc2cc3ccc(cc4ccc(cc5ccc(cc1n2)[nH]5)n4)[nH]3  porphyrin" > porphyrin.smi
obgen porphyrin.smi > porphyrin.mol
In [93]:
import __main__
__main__.pymol_argv = [ 'pymol', '-cp' ]
import pymol
pymol.finish_launching()
from pymol import cmd
In [94]:
from IPython.display import Image
In [95]:
cmd.do('''
reinit
bg white
load porphyrin.mol
show spheres, all
set sphere_scale, 0.2
set valence, on
ray
png pic1.png
''')
In [96]:
Image(filename='pic1.png')
Out[96]:
In [97]:
cmd.do('''

bg white
remove id 39+40
ray 
png pic2.png
''')
In [98]:
Image(filename='pic2.png')
Out[98]:
In [99]:
cmd.save('porphyrin.pdb', 'porphyrin')
In [41]:
%%bash 
#С помощью openbabel форматирую координаты в mol формате во входной файл для Mopac.
# С помощью аргумента -xk "PM6" зададим соответствующий тип параметризации.
babel -ipdb porphyrin.pdb -omop porphyrin_1opt.mop -xk "PM6"
In [42]:
%%bash
# На этом этапе происходит расчет молекулярных орбиталей для всех валентных электронов порфирина.
# Переформатирование из .out в .pdb
MOPAC2009.exe porphyrin_1opt.mop
In [43]:
%%bash
babel -imopout porphyrin_1opt.out -opdb porphyrin_1opt.pdb
In [100]:
cmd.do('''
reinit
bg white
load porphyrin_1opt.pdb
set valence, on
show spheres, all
set sphere_scale, 0.2
ray 
png pic3.png
''')
In [101]:
Image(filename='pic3.png')
Out[101]:
In [102]:
cmd.do('''
bg white
rotate x, 86
rotate z, -90
ray
png pic4.png
''')
In [103]:
Image(filename='pic4.png')
Out[103]:
In [17]:
%%bash
# Рассчет возбужденных состояний порфирина
# Копирую файл .mop
cp porphyrin_1opt.mop 1_opt_spectr.mop
echo "
cis c.i.=4 meci oldgeo
For porphyrin spectrum" >> 1_opt_spectr.mop
MOPAC2009.exe 1_opt_spectr.mop
bash: line 7: MOPAC2009.exe: command not found

In [11]:
# Выведем отдельно энергии электронных переходов
fl=open('/home/students/y12/rita501/term8/pr2/1_opt_spectr.out','r')
lines=fl.readlines()
for l in lines[-19:-6]:
    print l.split()
['STATE', 'ENERGY', '(EV)', 'Q.N.', 'SPIN', 'SYMMETRY', 'POLARIZATION']
['ABSOLUTE', 'RELATIVE', 'X', 'Y', 'Z']
[]
['1+', '0.000000', '0.000000', '1+', 'SINGLET', '????']
['2', '1.914982', '1.914982', '1', 'TRIPLET', '????']
['3', '2.267356', '2.267356', '2', 'SINGLET', '????']
['4', '2.464879', '2.464879', '2', 'TRIPLET', '????']
['5', '2.826510', '2.826510', '3', 'TRIPLET', '????']
['6', '3.365178', '3.365178', '4', 'TRIPLET', '????']
['7', '3.392490', '3.392490', '3', 'SINGLET', '????', '0.2399', '0.1995', '0.0013']
['8', '3.669238', '3.669238', '4', 'SINGLET', '????', '2.0363', '2.3850', '0.0129']
['9', '3.872141', '3.872141', '5', 'SINGLET', '????', '1.8024', '1.5312', '0.0100']
['The', '"+"', 'symbol', 'indicates', 'the', 'root', 'used.']

In [19]:
# Рассчитаем спектр поглощения
for i in lines[-15:-7]:
     l=i.split()
     k=float(l[2])
     print l[0], l[4], (constants.c*constants.h*(10**9)/codata.value('electron volt-joule relationship'))/k, 'nm'
fl.close()
2 TRIPLET 647.443124374 nm
3 SINGLET 546.822787952 nm
4 TRIPLET 503.003161291 nm
5 TRIPLET 438.647635848 nm
6 TRIPLET 368.432792916 nm
7 SINGLET 365.46664226 nm
8 SINGLET 337.901746684 nm
9 SINGLET 320.195449804 nm

In [22]:
%%bash
# Задание 3. Определение геометрии молекулы O=C1C=CC(=O)C=C1.
echo 'O=C1C=CC(=O)C=C1' >  benzoquinone.smi
obgen benzoquinone.smi > benzoquinone.mol

A T O M   T Y P E S

IDX	TYPE
1	7
2	3
3	2
4	2
5	3
6	7
7	2
8	2
9	5
10	5
11	5
12	5

F O R M A L   C H A R G E S

IDX	CHARGE
1	0.000000
2	0.000000
3	0.000000
4	0.000000
5	0.000000
6	0.000000
7	0.000000
8	0.000000
9	0.000000
10	0.000000
11	0.000000
12	0.000000

P A R T I A L   C H A R G E S

IDX	CHARGE
1	-0.570000
2	0.541200
3	-0.135600
4	-0.135600
5	0.541200
6	-0.570000
7	-0.135600
8	-0.135600
9	0.150000
10	0.150000
11	0.150000
12	0.150000

S E T T I N G   U P   C A L C U L A T I O N S

SETTING UP BOND CALCULATIONS...
SETTING UP ANGLE & STRETCH-BEND CALCULATIONS...
SETTING UP TORSION CALCULATIONS...
SETTING UP OOP CALCULATIONS...
SETTING UP VAN DER WAALS CALCULATIONS...
SETTING UP ELECTROSTATIC CALCULATIONS...

S T E E P E S T   D E S C E N T

STEPS = 500

STEP n       E(n)         E(n-1)    
------------------------------------
    0      16.578      ----
   10     2.13094     2.31535
   20     0.68590     0.80368
   30    -0.08085     0.00722
   40    -0.28925    -0.28127
   50    -0.76995    -0.76399
   60    -0.94816    -0.94219
   70    -0.98337    -0.97925
   80    -1.00316    -0.99928
   90    -1.02857    -1.02531
  100    -1.04055    -1.03863
  110    -1.05610    -1.05563
    STEEPEST DESCENT HAS CONVERGED

W E I G H T E D   R O T O R   S E A R C H

  NUMBER OF ROTATABLE BONDS: 0
  NUMBER OF POSSIBLE ROTAMERS: 1
  GENERATED ONLY ONE CONFORMER


S T E E P E S T   D E S C E N T

STEPS = 500

STEP n       E(n)         E(n-1)    
------------------------------------
    0      -1.104      ----
   10    -1.10599    -1.10533
   20    -1.10647    -1.10682
   30    -1.10754    -1.10718
   40    -1.10821    -1.10802
   50    -1.10875    -1.10865
   60    -1.10868    -1.10915
   70    -1.10936    -1.10872
   80    -1.10984    -1.10950
   90    -1.11020    -1.11002
  100    -1.11049    -1.11039
  110    -1.11009    -1.11067
  120    -1.11059    -1.10990
  130    -1.11092    -1.11055
  140    -1.11115    -1.11095
  150    -1.11132    -1.11121
  160    -1.11067    -1.11139
  170    -1.11113    -1.11152
  180    -1.11141    -1.11095
  190    -1.11159    -1.11133
  200    -1.11171    -1.11156
  210    -1.11077    -1.11171
  220    -1.11128    -1.11181
  230    -1.11158    -1.11099
  240    -1.11176    -1.11142
  250    -1.11188    -1.11168
  260    -1.11195    -1.11183
  270    -1.11119    -1.11193
  280    -1.11156    -1.11200
  290    -1.11178    -1.11131
  300    -1.11192    -1.11164
  310    -1.11200    -1.11184
  320    -1.11205    -1.11196
  330    -1.11140    -1.11203
  340    -1.11171    -1.11103
  350    -1.11189    -1.11148
  360    -1.11199    -1.11176
  370    -1.11206    -1.11192
  380    -1.11111    -1.11202
  390    -1.11153    -1.11208
  400    -1.11179    -1.11121
  410    -1.11194    -1.11159
  420    -1.11204    -1.11183
  430    -1.11209    -1.11197
  440    -1.11125    -1.11205
  450    -1.11162    -1.11210
  460    -1.11185    -1.11133
  470    -1.11198    -1.11167
  480    -1.11206    -1.11188
  490    -1.11211    -1.11200
  500    -1.11137    -1.11207

In [56]:
cmd.do('''
reinit
bg white
load benzoquinone.mol
set valence, on
show spheres, all
set sphere_scale, 0.2
ray 
png pic5.png
''')
In [57]:
Image(filename='pic5.png')
Out[57]:
In [74]:
cmd.save('benzoquinone.pdb', 'benzoquinone')
In [59]:
#Вид сбоку
cmd.do('''
rotate x, -70
ray
png pic5_70.png
''')
In [60]:
Image(filename='pic5_70.png')
Out[60]:
In [105]:
%%bash
# Запустим MOPAC
babel -ipdb benzoquinone.pdb -omop  benzoquinone.mop -xk "PM6"
In []:
MOPAC2009.exe benzoquinone.mop
babel -imopout benzoquinone.out -opdb benzoquinone_mopac.pdb
In [62]:
# Сравним молекулы:
cmd.do('''
reinit
bg white
load benzoquinone_mopac.pdb
set valence, on
show spheres, all
set sphere_scale, 0.2
ray 
png pic6.png
''')
In [65]:
Image(filename='pic6.png')
Out[65]:
In [66]:
# Для начала в первую строчку файла .mop добавим CHARGE=-2. Затем укажем те атомы, на которых должен находиться отрицательный заряд, – атомы кислорода.
with open("benzoquinone.mop") as f,open("benzoquinone_charge.mop",'w') as o:
    data=f.read()
    data=data.replace("PM6\benzoquinone.pdb","PM6 CHARGE=-2\benzoquinone.pdb")
    o.write(data)
with open("benzoquinone_charge.mop") as f,open("benzoquinone_charge2.mop",'w') as o:
    data=f.read()
    data=data.replace("O","O(-)")
    o.write(data)  
In [67]:
%%bash
MOPAC2009.exe benzoquinone_charge2.mop
babel -imopout benzoquinone_charge2.out -opdb benzoquinone_charge2.pdb
In [72]:
cmd.do('''
reinit
bg white
load benzoquinone_charge2.pdb
set valence, on
show spheres, all
set sphere_scale, 0.2
ray 
png pic7.png
''')
In [73]:
Image(filename='pic7.png')
Out[73]: