from subprocess import run
%matplotlib inline
import pandas as pd
import matplotlib.pyplot as plt
! export GMX_MAXBACKUP=-1
Скачаем все необходимые файлы:
! rm -rf *.mdp etane.gro
! wget -q http://kodomo.fbb.msu.ru/FBB/year_08/term6/etane.gro http://kodomo.fbb.msu.ru/FBB/year_08/term6/be.mdp http://kodomo.fbb.msu.ru/FBB/year_08/term6/vr.mdp http://kodomo.fbb.msu.ru/FBB/year_08/term6/nh.mdp http://kodomo.fbb.msu.ru/FBB/year_08/term6/an.mdp http://kodomo.fbb.msu.ru/FBB/year_08/term6/sd.mdp
Подготовим файл координат etane.gro и файл топологии et.top.
В поле OPLS тип функционала для торсионных углов не "1". Посмотрим файл /usr/share/gromacs/top/oplsaa.ff/forcefield.itp Там есть ссылка на файл с параметрами для ковалентных взаимодействий ffbonded.itp, где указано, что нужное значение для типа dihedrals = 3. Типы атомов: opls_135 для углерода и opls_140 для водорода согласно /usr/share/gromacs/top/oplsaa.ff/atomtypes.atp
def run_and_check(command):
print(f'Running the command: {command}')
result = run(command, shell=True, capture_output=True, text=True)
if result.returncode != 0:
print(result.stderr)
t_stats = ['be', 'vr', 'nh', 'sd']
for thermo in t_stats:
# В более поздних версиях Gromacs'а требуется, чтобы rvdw = rcoulomb. Сделаем их равными 0.70.
run_and_check(f'sed -ie "s/0.74/0.70/" {thermo}.mdp')
run_and_check(f'gmx grompp -f {thermo}.mdp -c et.gro -p et.top -o et_{thermo}.tpr')
run_and_check(f'gmx mdrun -deffnm et_{thermo} -v -nt 1')
run_and_check(f'echo 0 | gmx trjconv -f et_{thermo}.trr -s et_{thermo}.tpr -o et_{thermo}.pdb')
for thermo in t_stats:
run_and_check(f'echo 8 9 | gmx energy -f et_{thermo}.edr -o et_{thermo}.xvg')
df = pd.read_table(f'et_{thermo}.xvg', skiprows=25, delim_whitespace=True, names=['Time, ps','Potential E, kJ/mol','Kinetic E, kJ/mol'])
df.plot(x='Time, ps', title=thermo)
for thermo in t_stats:
print(f'Thermostat {thermo}')
run_and_check(f'echo 0 | gmx distance -f et_{thermo}.trr -s et_{thermo}.tpr -n b.ndx -oh bond_{thermo}.xvg -xvg none ')
df_bar = pd.read_fwf(f'bond_{thermo}.xvg', names=['Bond Length, nm', 'Density'])
plt.bar(df_bar['Bond Length, nm'], df_bar['Density'], width=0.005)
plt.show()