From 423577e3580a1a0f833e397051d258636a237760 Mon Sep 17 00:00:00 2001 From: drelatgithub Date: Mon, 18 May 2015 22:55:11 +0800 Subject: [PATCH 01/13] develop branch upload test --- .../GraduateProject_DNASelfAssembling.cpp | 8 ++++++-- .../GraduateProject_PatchesAndPresets.cpp | 16 +++++++++++----- .../GraduateProject_PatchesAndPresets.h | 1 + GraduateProject_DNASelfAssembling/stdafx.h | 6 +++++- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.cpp b/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.cpp index 8f4aabc..71e023c 100644 --- a/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.cpp +++ b/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.cpp @@ -3,6 +3,8 @@ #include "stdafx.h" +mt19937 gen(123456); + int programInitiation(){ ornt2bpornt_init(); unitcell_init(); @@ -13,8 +15,10 @@ int _tmain(int argc, _TCHAR* argv[]) programInitiation(); patchPreset(); - - + for (int i = 0; i < N; i++){ + cout << i << '\t'; + mol[i].displayPatch(); + } return 0; } diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.cpp b/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.cpp index f7f1b5d..ccbc140 100644 --- a/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.cpp +++ b/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.cpp @@ -5,10 +5,7 @@ atom_in_unitcell atom_in_unitcell::set(int nx, int ny, int nz, int nsd, int norn sd = nsd; int mainOrnt = nornt0; int subOrnt = 0, subOrnt_as_pow = 7 - nornt0^nornt1; - while (subOrnt_as_pow > 1){ - subOrnt_as_pow >>= 1; - subOrnt++; - } + for (; subOrnt_as_pow > 1; subOrnt_as_pow >>= 1)subOrnt++; ornt = mainOrnt + 8 * subOrnt; return *this; } @@ -28,8 +25,10 @@ int unitcell_init(){ DNAmol::DNAmol(){ px.x = px.y = px.z = 0; ornt = 0; - for (int i = 0; i < 4; i++){ + int i, j; + for (i = 0; i < 4; i++){ correctbond[i] = -1; + for (j = 0; j < 8; j++)patch[i][j] = 'T'; } } DNAmol DNAmol::put(int nx, int ny, int nz, int nornt){ @@ -42,6 +41,13 @@ DNAmol DNAmol::put(const atom_in_unitcell &a, int x_init, int y_init, int z_init ornt = a.ornt; return *this; } +int DNAmol::displayPatch()const{ + for (int i = 0; i < 4; i++){ + cout.write(patch[i], 8); + } + cout << endl; + return 0; +} int stage[_Nx][_Ny][_Nz]; // To store DNAmol serial. -1 if not occupied. Using periodic boundary conditions. DNAmol *mol; int N; // Total molecules. diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.h b/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.h index 06bd024..826128c 100644 --- a/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.h +++ b/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.h @@ -17,6 +17,7 @@ struct DNAmol{ DNAmol(); DNAmol put(int nx, int ny, int nz, int nornt); DNAmol put(const atom_in_unitcell &a, int x_init, int y_init, int z_init); + int displayPatch()const; }; extern DNAmol *mol; extern int stage[_Nx][_Ny][_Nz]; // To store DNAmol serial. -1 if not occupied. Using periodic boundary conditions. diff --git a/GraduateProject_DNASelfAssembling/stdafx.h b/GraduateProject_DNASelfAssembling/stdafx.h index 6b55041..06a10fc 100644 --- a/GraduateProject_DNASelfAssembling/stdafx.h +++ b/GraduateProject_DNASelfAssembling/stdafx.h @@ -13,10 +13,14 @@ // TODO: 在此处引用程序需要的其他头文件 #include #include +#include using namespace std; #include #include"GraduateProject_PositionAndOrientation.h" -#include"GraduateProject_PatchesAndPresets.h" \ No newline at end of file +#include"GraduateProject_PatchesAndPresets.h" + + +extern mt19937 gen; \ No newline at end of file From 14f70531df5100c243d73edd977e7434fec3b9c9 Mon Sep 17 00:00:00 2001 From: drelatgithub Date: Tue, 19 May 2015 01:39:00 +0800 Subject: [PATCH 02/13] patches assigned --- .../GraduateProject_PatchesAndPresets.cpp | 18 +++++++++++++++++- .../GraduateProject_PatchesAndPresets.h | 3 +++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.cpp b/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.cpp index ccbc140..7f79eea 100644 --- a/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.cpp +++ b/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.cpp @@ -52,6 +52,16 @@ int stage[_Nx][_Ny][_Nz]; // To store DNAmol serial. -1 if not occupied. Using p DNAmol *mol; int N; // Total molecules. +char nt[4] = { 'A', 'C', 'G', 'T' }; +int ntSerial(char which_nt){ + switch (which_nt){ + case'A':return 0; + case'C':return 1; + case'G':return 2; + case'T':return 3; + } +} + int stageClear(){ int i, j, k; for (i = 0; i < _Nx; i++){ @@ -96,6 +106,7 @@ int correctbonding(int n0serial, int n01x, int n01y, int n01z){ int ornt1 = 7 - ornt0; int n0ps = -1, n1ps = -1; // patch serial for the right bonding. -1 if not exist. int m; + int temp_ntSerial; for (m = 0; m < 4; m++){ if (ornt2bpornt[mol[n0serial].ornt][m] == ornt0){ n0ps = m; break; @@ -110,7 +121,12 @@ int correctbonding(int n0serial, int n01x, int n01y, int n01z){ mol[n0serial].correctbond[n0ps] = n1serial; mol[n1serial].correctbond[n1ps] = n0serial; // patch assign - + static uniform_int_distribution<> patchDis(0, 3); + for (int i = 0; i < 8; i++){ + temp_ntSerial = patchDis(gen); + mol[n0serial].patch[n0ps][i] = nt[temp_ntSerial]; + mol[n1serial].patch[n1ps][7 - i] = nt[3 - temp_ntSerial]; + } return 0; } return 1; diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.h b/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.h index 826128c..2729b65 100644 --- a/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.h +++ b/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.h @@ -23,4 +23,7 @@ extern DNAmol *mol; extern int stage[_Nx][_Ny][_Nz]; // To store DNAmol serial. -1 if not occupied. Using periodic boundary conditions. extern int N; // Total molecules. +extern char nt[4]; +int ntSerial(char which_nt); + int patchPreset(); \ No newline at end of file From e8139bd6f95f01b8949d9c5a16ee4c1e1d9eedd5 Mon Sep 17 00:00:00 2001 From: drelatgithub Date: Wed, 20 May 2015 00:30:20 +0800 Subject: [PATCH 03/13] initial distribution --- .../GraduateProject_DNASelfAssembling.cpp | 5 +++-- .../GraduateProject_DNASelfAssembling.vcxproj | 2 ++ ...raduateProject_DNASelfAssembling.vcxproj.filters | 6 ++++++ .../GraduateProject_PatchesAndPresets.cpp | 13 +++++++++++++ .../GraduateProject_PatchesAndPresets.h | 1 + GraduateProject_DNASelfAssembling/stdafx.h | 1 + 6 files changed, 26 insertions(+), 2 deletions(-) diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.cpp b/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.cpp index 71e023c..83364c8 100644 --- a/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.cpp +++ b/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.cpp @@ -14,12 +14,13 @@ int _tmain(int argc, _TCHAR* argv[]) { programInitiation(); patchPreset(); + simulationPrepare(); for (int i = 0; i < N; i++){ - cout << i << '\t'; - mol[i].displayPatch(); + cout << i << '\t' << mol[i].px << endl; } + return 0; } diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.vcxproj b/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.vcxproj index 2683d53..2b6389e 100644 --- a/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.vcxproj +++ b/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.vcxproj @@ -81,6 +81,7 @@ + @@ -88,6 +89,7 @@ + Create Create diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.vcxproj.filters b/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.vcxproj.filters index ee49a70..25f3fd9 100644 --- a/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.vcxproj.filters +++ b/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.vcxproj.filters @@ -30,6 +30,9 @@ 澶存枃浠 + + 澶存枃浠 + @@ -44,5 +47,8 @@ 婧愭枃浠 + + 婧愭枃浠 + \ No newline at end of file diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.cpp b/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.cpp index 7f79eea..65d8faa 100644 --- a/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.cpp +++ b/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.cpp @@ -48,6 +48,13 @@ int DNAmol::displayPatch()const{ cout << endl; return 0; } +int DNAmol::displayPatch(ofstream &out)const{ + for (int i = 0; i < 4; i++){ + out.write(patch[i], 8); + } + out << endl; + return 0; +} int stage[_Nx][_Ny][_Nz]; // To store DNAmol serial. -1 if not occupied. Using periodic boundary conditions. DNAmol *mol; int N; // Total molecules. @@ -146,11 +153,17 @@ int nucleotidePreset(){ } } } + ofstream out("F:\\DNAPatches.txt"); + for (m = 0; m < N; m++){ + mol[m].displayPatch(out); + } + out.close(); return 0; } int patchPreset(){ stageClear(); molPreset(); nucleotidePreset(); + stageClear(); return 0; } \ No newline at end of file diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.h b/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.h index 2729b65..dcb5320 100644 --- a/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.h +++ b/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.h @@ -18,6 +18,7 @@ struct DNAmol{ DNAmol put(int nx, int ny, int nz, int nornt); DNAmol put(const atom_in_unitcell &a, int x_init, int y_init, int z_init); int displayPatch()const; + int displayPatch(ofstream &out)const; }; extern DNAmol *mol; extern int stage[_Nx][_Ny][_Nz]; // To store DNAmol serial. -1 if not occupied. Using periodic boundary conditions. diff --git a/GraduateProject_DNASelfAssembling/stdafx.h b/GraduateProject_DNASelfAssembling/stdafx.h index 06a10fc..4c791d9 100644 --- a/GraduateProject_DNASelfAssembling/stdafx.h +++ b/GraduateProject_DNASelfAssembling/stdafx.h @@ -21,6 +21,7 @@ using namespace std; #include"GraduateProject_PositionAndOrientation.h" #include"GraduateProject_PatchesAndPresets.h" +#include"GraduateProject_Simulation.h" extern mt19937 gen; \ No newline at end of file From a6402721438ebcdf656c9f143042274a469e2194 Mon Sep 17 00:00:00 2001 From: drelatgithub Date: Wed, 20 May 2015 00:35:50 +0800 Subject: [PATCH 04/13] Revert "initial distribution" This reverts commit e8139bd6f95f01b8949d9c5a16ee4c1e1d9eedd5. --- .../GraduateProject_DNASelfAssembling.cpp | 5 ++--- .../GraduateProject_DNASelfAssembling.vcxproj | 2 -- ...raduateProject_DNASelfAssembling.vcxproj.filters | 6 ------ .../GraduateProject_PatchesAndPresets.cpp | 13 ------------- .../GraduateProject_PatchesAndPresets.h | 1 - GraduateProject_DNASelfAssembling/stdafx.h | 1 - 6 files changed, 2 insertions(+), 26 deletions(-) diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.cpp b/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.cpp index 83364c8..71e023c 100644 --- a/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.cpp +++ b/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.cpp @@ -14,13 +14,12 @@ int _tmain(int argc, _TCHAR* argv[]) { programInitiation(); patchPreset(); - simulationPrepare(); for (int i = 0; i < N; i++){ - cout << i << '\t' << mol[i].px << endl; + cout << i << '\t'; + mol[i].displayPatch(); } - return 0; } diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.vcxproj b/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.vcxproj index 2b6389e..2683d53 100644 --- a/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.vcxproj +++ b/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.vcxproj @@ -81,7 +81,6 @@ - @@ -89,7 +88,6 @@ - Create Create diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.vcxproj.filters b/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.vcxproj.filters index 25f3fd9..ee49a70 100644 --- a/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.vcxproj.filters +++ b/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.vcxproj.filters @@ -30,9 +30,6 @@ 澶存枃浠 - - 澶存枃浠 - @@ -47,8 +44,5 @@ 婧愭枃浠 - - 婧愭枃浠 - \ No newline at end of file diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.cpp b/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.cpp index 65d8faa..7f79eea 100644 --- a/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.cpp +++ b/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.cpp @@ -48,13 +48,6 @@ int DNAmol::displayPatch()const{ cout << endl; return 0; } -int DNAmol::displayPatch(ofstream &out)const{ - for (int i = 0; i < 4; i++){ - out.write(patch[i], 8); - } - out << endl; - return 0; -} int stage[_Nx][_Ny][_Nz]; // To store DNAmol serial. -1 if not occupied. Using periodic boundary conditions. DNAmol *mol; int N; // Total molecules. @@ -153,17 +146,11 @@ int nucleotidePreset(){ } } } - ofstream out("F:\\DNAPatches.txt"); - for (m = 0; m < N; m++){ - mol[m].displayPatch(out); - } - out.close(); return 0; } int patchPreset(){ stageClear(); molPreset(); nucleotidePreset(); - stageClear(); return 0; } \ No newline at end of file diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.h b/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.h index dcb5320..2729b65 100644 --- a/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.h +++ b/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.h @@ -18,7 +18,6 @@ struct DNAmol{ DNAmol put(int nx, int ny, int nz, int nornt); DNAmol put(const atom_in_unitcell &a, int x_init, int y_init, int z_init); int displayPatch()const; - int displayPatch(ofstream &out)const; }; extern DNAmol *mol; extern int stage[_Nx][_Ny][_Nz]; // To store DNAmol serial. -1 if not occupied. Using periodic boundary conditions. diff --git a/GraduateProject_DNASelfAssembling/stdafx.h b/GraduateProject_DNASelfAssembling/stdafx.h index 4c791d9..06a10fc 100644 --- a/GraduateProject_DNASelfAssembling/stdafx.h +++ b/GraduateProject_DNASelfAssembling/stdafx.h @@ -21,7 +21,6 @@ using namespace std; #include"GraduateProject_PositionAndOrientation.h" #include"GraduateProject_PatchesAndPresets.h" -#include"GraduateProject_Simulation.h" extern mt19937 gen; \ No newline at end of file From 8e79e0c9c13e47fe07f7329f8c41cbde5dce49a5 Mon Sep 17 00:00:00 2001 From: drelatgithub Date: Wed, 20 May 2015 00:36:23 +0800 Subject: [PATCH 05/13] initial distribution --- .../GraduateProject_Simulation.cpp | 36 +++++++++++++++++++ .../GraduateProject_Simulation.h | 3 ++ 2 files changed, 39 insertions(+) create mode 100644 GraduateProject_DNASelfAssembling/GraduateProject_Simulation.cpp create mode 100644 GraduateProject_DNASelfAssembling/GraduateProject_Simulation.h diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_Simulation.cpp b/GraduateProject_DNASelfAssembling/GraduateProject_Simulation.cpp new file mode 100644 index 0000000..f59d18e --- /dev/null +++ b/GraduateProject_DNASelfAssembling/GraduateProject_Simulation.cpp @@ -0,0 +1,36 @@ +#include"stdafx.h" + +/* + The algorithm used in this function has LOW efficiency, and needs to be improved. + + We put the DNA molecules in the lattice randomly in the following manner: + 1: generate a random number as the position in the lattice; + 2: if the position is not taken, put the molecule in it, otherwise repeat 1; + 3: repeat 1 - 2 for all molecules. + + The ratio of useful to useless repetitions could be extremely LOW when the lattice becomes crowded. + Assume the lattice with n different positions in which m is already taken, + then the expectation value for the repetitions required to put a new molecule is n/(n-m). + The overall time complexity to put k molecules is O(n ln(n/(n-k))) + where the best case is O(k), and the worst case is O(\infty). + + This information should be removed after revising. +*/ +int simulationPrepare(){ + static uniform_int_distribution transDis_x(0, _Nx - 1); + static uniform_int_distribution transDis_y(0, _Ny - 1); + static uniform_int_distribution transDis_z(0, _Nz - 1); + static uniform_int_distribution<> orntDis(0, 23); + int x, y, z; + for (int m = 0; m < N; m++){ + do{ + x = transDis_x(gen); + y = transDis_y(gen); + z = transDis_z(gen); + } while (stage[x][y][z] >= 0); + stage[x][y][z] = m; + mol[m].put(x, y, z, orntDis(gen)); + } + + return 0; +} \ No newline at end of file diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_Simulation.h b/GraduateProject_DNASelfAssembling/GraduateProject_Simulation.h new file mode 100644 index 0000000..a7cbfb7 --- /dev/null +++ b/GraduateProject_DNASelfAssembling/GraduateProject_Simulation.h @@ -0,0 +1,3 @@ +#pragma once + +int simulationPrepare(); \ No newline at end of file From 1ea2cf868a2fd2a54faa492d5185d78938dde562 Mon Sep 17 00:00:00 2001 From: drelatgithub Date: Wed, 20 May 2015 00:41:21 +0800 Subject: [PATCH 06/13] change 2 --- .../GraduateProject_DNASelfAssembling.cpp | 5 +++-- .../GraduateProject_PatchesAndPresets.cpp | 13 +++++++++++++ .../GraduateProject_PatchesAndPresets.h | 1 + GraduateProject_DNASelfAssembling/stdafx.h | 1 + 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.cpp b/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.cpp index 71e023c..83364c8 100644 --- a/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.cpp +++ b/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.cpp @@ -14,12 +14,13 @@ int _tmain(int argc, _TCHAR* argv[]) { programInitiation(); patchPreset(); + simulationPrepare(); for (int i = 0; i < N; i++){ - cout << i << '\t'; - mol[i].displayPatch(); + cout << i << '\t' << mol[i].px << endl; } + return 0; } diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.cpp b/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.cpp index 7f79eea..65d8faa 100644 --- a/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.cpp +++ b/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.cpp @@ -48,6 +48,13 @@ int DNAmol::displayPatch()const{ cout << endl; return 0; } +int DNAmol::displayPatch(ofstream &out)const{ + for (int i = 0; i < 4; i++){ + out.write(patch[i], 8); + } + out << endl; + return 0; +} int stage[_Nx][_Ny][_Nz]; // To store DNAmol serial. -1 if not occupied. Using periodic boundary conditions. DNAmol *mol; int N; // Total molecules. @@ -146,11 +153,17 @@ int nucleotidePreset(){ } } } + ofstream out("F:\\DNAPatches.txt"); + for (m = 0; m < N; m++){ + mol[m].displayPatch(out); + } + out.close(); return 0; } int patchPreset(){ stageClear(); molPreset(); nucleotidePreset(); + stageClear(); return 0; } \ No newline at end of file diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.h b/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.h index 2729b65..dcb5320 100644 --- a/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.h +++ b/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.h @@ -18,6 +18,7 @@ struct DNAmol{ DNAmol put(int nx, int ny, int nz, int nornt); DNAmol put(const atom_in_unitcell &a, int x_init, int y_init, int z_init); int displayPatch()const; + int displayPatch(ofstream &out)const; }; extern DNAmol *mol; extern int stage[_Nx][_Ny][_Nz]; // To store DNAmol serial. -1 if not occupied. Using periodic boundary conditions. diff --git a/GraduateProject_DNASelfAssembling/stdafx.h b/GraduateProject_DNASelfAssembling/stdafx.h index 06a10fc..4c791d9 100644 --- a/GraduateProject_DNASelfAssembling/stdafx.h +++ b/GraduateProject_DNASelfAssembling/stdafx.h @@ -21,6 +21,7 @@ using namespace std; #include"GraduateProject_PositionAndOrientation.h" #include"GraduateProject_PatchesAndPresets.h" +#include"GraduateProject_Simulation.h" extern mt19937 gen; \ No newline at end of file From 4ab8ac00b10861ca11c435fd3254a7246a840fdc Mon Sep 17 00:00:00 2001 From: drelatgithub Date: Wed, 20 May 2015 00:45:23 +0800 Subject: [PATCH 07/13] change 3 --- .../GraduateProject_DNASelfAssembling.vcxproj | 2 ++ .../GraduateProject_DNASelfAssembling.vcxproj.filters | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.vcxproj b/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.vcxproj index 2683d53..2b6389e 100644 --- a/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.vcxproj +++ b/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.vcxproj @@ -81,6 +81,7 @@ + @@ -88,6 +89,7 @@ + Create Create diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.vcxproj.filters b/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.vcxproj.filters index ee49a70..25f3fd9 100644 --- a/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.vcxproj.filters +++ b/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.vcxproj.filters @@ -30,6 +30,9 @@ 澶存枃浠 + + 澶存枃浠 + @@ -44,5 +47,8 @@ 婧愭枃浠 + + 婧愭枃浠 + \ No newline at end of file From e1939e508623bd5c762f05a0a7bed98bc391ed05 Mon Sep 17 00:00:00 2001 From: drelatgithub Date: Thu, 21 May 2015 01:12:54 +0800 Subject: [PATCH 08/13] 20150521 daily --- .../GraduateProject_DNASelfAssembling.cpp | 1 + .../GraduateProject_Simulation.cpp | 45 ++++++++++++++++--- .../GraduateProject_Simulation.h | 3 +- 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.cpp b/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.cpp index 83364c8..26ef0d4 100644 --- a/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.cpp +++ b/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.cpp @@ -15,6 +15,7 @@ int _tmain(int argc, _TCHAR* argv[]) programInitiation(); patchPreset(); simulationPrepare(); + simulationProcess(); for (int i = 0; i < N; i++){ cout << i << '\t' << mol[i].px << endl; diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_Simulation.cpp b/GraduateProject_DNASelfAssembling/GraduateProject_Simulation.cpp index f59d18e..478abe4 100644 --- a/GraduateProject_DNASelfAssembling/GraduateProject_Simulation.cpp +++ b/GraduateProject_DNASelfAssembling/GraduateProject_Simulation.cpp @@ -1,5 +1,20 @@ #include"stdafx.h" +bool couldPlaceMolecule(int x, int y, int z){ + int i, j, k; + ppos npx; + for (i = -1; i <= 1; i++){ + for (j = -1; j <= 1; j++){ + for (k = -1; k <= 1; k++){ + npx = ppos(x + i, y + j, z + k); + if (i*i + j*j + k*k != 3 && stage[npx.x][npx.y][npx.z] >= 0){ + return false; + } + } + } + } + return true; +} /* The algorithm used in this function has LOW efficiency, and needs to be improved. @@ -14,23 +29,41 @@ The overall time complexity to put k molecules is O(n ln(n/(n-k))) where the best case is O(k), and the worst case is O(\infty). - This information should be removed after revising. + As for this case, every DNA molecule would in average consume 4 of the lattice positions, + thus making the stage easily get crowded. + + ====== This information should be removed after revising. ====== */ int simulationPrepare(){ - static uniform_int_distribution transDis_x(0, _Nx - 1); - static uniform_int_distribution transDis_y(0, _Ny - 1); - static uniform_int_distribution transDis_z(0, _Nz - 1); - static uniform_int_distribution<> orntDis(0, 23); + uniform_int_distribution transDis_x(0, _Nx - 1); + uniform_int_distribution transDis_y(0, _Ny - 1); + uniform_int_distribution transDis_z(0, _Nz - 1); + uniform_int_distribution<> orntDis(0, 23); int x, y, z; for (int m = 0; m < N; m++){ do{ x = transDis_x(gen); y = transDis_y(gen); z = transDis_z(gen); - } while (stage[x][y][z] >= 0); + } while (!couldPlaceMolecule(x, y, z)); stage[x][y][z] = m; mol[m].put(x, y, z, orntDis(gen)); } + return 0; +} + +#define k_B 1.381E-23 +#define N_A 6.023E23 + + +int moveStep(int s){ + + return 0; +} +int simulationProcess(){ + int totalSteps = 10000; + int step = 0; + return 0; } \ No newline at end of file diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_Simulation.h b/GraduateProject_DNASelfAssembling/GraduateProject_Simulation.h index a7cbfb7..d8d4485 100644 --- a/GraduateProject_DNASelfAssembling/GraduateProject_Simulation.h +++ b/GraduateProject_DNASelfAssembling/GraduateProject_Simulation.h @@ -1,3 +1,4 @@ #pragma once -int simulationPrepare(); \ No newline at end of file +int simulationPrepare(); +int simulationProcess(); \ No newline at end of file From a2ca5d1b7905ccf18dd980a1296901aacdc7b805 Mon Sep 17 00:00:00 2001 From: drelatgithub Date: Fri, 22 May 2015 01:03:53 +0800 Subject: [PATCH 09/13] 20150521 daily --- .../GraduateProject_DNASelfAssembling.cpp | 5 - .../GraduateProject_PatchesAndPresets.cpp | 34 +++-- .../GraduateProject_PatchesAndPresets.h | 5 + .../GraduateProject_Simulation.cpp | 129 +++++++++++++++--- .../GraduateProject_Simulation.h | 6 + 5 files changed, 140 insertions(+), 39 deletions(-) diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.cpp b/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.cpp index 26ef0d4..ce0a2bc 100644 --- a/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.cpp +++ b/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.cpp @@ -17,11 +17,6 @@ int _tmain(int argc, _TCHAR* argv[]) simulationPrepare(); simulationProcess(); - for (int i = 0; i < N; i++){ - cout << i << '\t' << mol[i].px << endl; - } - - return 0; } diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.cpp b/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.cpp index 65d8faa..42281ac 100644 --- a/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.cpp +++ b/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.cpp @@ -55,6 +55,14 @@ int DNAmol::displayPatch(ofstream &out)const{ out << endl; return 0; } +int DNAmol::findPatchSerial(int whichOrnt)const{ // Find the patch serial in the designated orientation. -1 if not found. + for (int m = 0; m < 4; m++){ + if (ornt2bpornt[ornt][m] == whichOrnt){ + return m; + } + } + return -1; +} int stage[_Nx][_Ny][_Nz]; // To store DNAmol serial. -1 if not occupied. Using periodic boundary conditions. DNAmol *mol; int N; // Total molecules. @@ -68,6 +76,17 @@ int ntSerial(char which_nt){ case'T':return 3; } } +int ntSerialPair[4] = { 3, 2, 1, 0 }; +char ntPair(char which_nt){ + return nt[ntSerialPair[ntSerial(which_nt)]]; +} +int couldPatchInteract[4][4] = { + { 0, 1, 1, 0 }, + { 1, 0, 0, 1 }, + { 1, 0, 0, 1 }, + { 0, 1, 1, 0 } +}; +int isPatchConsequent[4] = { 1, 0, 0, 1 }; int stageClear(){ int i, j, k; @@ -112,19 +131,10 @@ int correctbonding(int n0serial, int n01x, int n01y, int n01z){ int ornt0 = 4 * (n01x + 1) / 2 + 2 * (n01y + 1) / 2 + (n01z + 1) / 2; int ornt1 = 7 - ornt0; int n0ps = -1, n1ps = -1; // patch serial for the right bonding. -1 if not exist. - int m; int temp_ntSerial; - for (m = 0; m < 4; m++){ - if (ornt2bpornt[mol[n0serial].ornt][m] == ornt0){ - n0ps = m; break; - } - } - for (m = 0; m < 4; m++){ - if (ornt2bpornt[mol[n1serial].ornt][m] == ornt1){ - n1ps = m; break; - } - } - if (n0ps >= 0 && n1ps >= 0 && abs(n0ps - n1ps) == 2){ + n0ps = mol[n0serial].findPatchSerial(ornt0); + n1ps = mol[n1serial].findPatchSerial(ornt1); + if (n0ps >= 0 && n1ps >= 0 && couldPatchInteract[n0ps][n1ps]){ mol[n0serial].correctbond[n0ps] = n1serial; mol[n1serial].correctbond[n1ps] = n0serial; // patch assign diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.h b/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.h index dcb5320..b6a47eb 100644 --- a/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.h +++ b/GraduateProject_DNASelfAssembling/GraduateProject_PatchesAndPresets.h @@ -19,6 +19,7 @@ struct DNAmol{ DNAmol put(const atom_in_unitcell &a, int x_init, int y_init, int z_init); int displayPatch()const; int displayPatch(ofstream &out)const; + int findPatchSerial(int whichOrnt)const; // Find the patch serial in the designated orientation. -1 if not found. }; extern DNAmol *mol; extern int stage[_Nx][_Ny][_Nz]; // To store DNAmol serial. -1 if not occupied. Using periodic boundary conditions. @@ -26,5 +27,9 @@ extern int N; // Total molecules. extern char nt[4]; int ntSerial(char which_nt); +extern int ntSerialPair[4]; +char ntPair(char which_nt); +extern int couldPatchInteract[4][4]; +extern int isPatchConsequent[4]; // If the nucleotide sequence in a patch is 5'-3', it is consequent. int patchPreset(); \ No newline at end of file diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_Simulation.cpp b/GraduateProject_DNASelfAssembling/GraduateProject_Simulation.cpp index 478abe4..a1bdf06 100644 --- a/GraduateProject_DNASelfAssembling/GraduateProject_Simulation.cpp +++ b/GraduateProject_DNASelfAssembling/GraduateProject_Simulation.cpp @@ -15,26 +15,26 @@ bool couldPlaceMolecule(int x, int y, int z){ } return true; } -/* - The algorithm used in this function has LOW efficiency, and needs to be improved. - - We put the DNA molecules in the lattice randomly in the following manner: - 1: generate a random number as the position in the lattice; - 2: if the position is not taken, put the molecule in it, otherwise repeat 1; - 3: repeat 1 - 2 for all molecules. - - The ratio of useful to useless repetitions could be extremely LOW when the lattice becomes crowded. - Assume the lattice with n different positions in which m is already taken, - then the expectation value for the repetitions required to put a new molecule is n/(n-m). - The overall time complexity to put k molecules is O(n ln(n/(n-k))) - where the best case is O(k), and the worst case is O(\infty). - - As for this case, every DNA molecule would in average consume 4 of the lattice positions, - thus making the stage easily get crowded. - - ====== This information should be removed after revising. ====== -*/ int simulationPrepare(){ + /* + The following algorithm used has LOW efficiency, and needs to be improved. + + We put the DNA molecules in the lattice randomly in the following manner: + 1: generate a random number as the position in the lattice; + 2: if the position is not taken, put the molecule in it, otherwise repeat 1; + 3: repeat 1 - 2 for all molecules. + + The ratio of useful to useless repetitions could be extremely LOW when the lattice becomes crowded. + Assume the lattice with n different positions in which m is already taken, + then the expectation value for the repetitions required to put a new molecule is n/(n-m). + The overall time complexity to put k molecules is O(n ln(n/(n-k))) + where the best case is O(k), and the worst case is O(\infty). + + As for this case, every DNA molecule would in average consume 4 of the lattice positions, + thus making the stage easily get crowded. + + ====== This information should be removed after revising. ====== + */ uniform_int_distribution transDis_x(0, _Nx - 1); uniform_int_distribution transDis_y(0, _Ny - 1); uniform_int_distribution transDis_z(0, _Nz - 1); @@ -53,17 +53,102 @@ int simulationPrepare(){ return 0; } -#define k_B 1.381E-23 -#define N_A 6.023E23 +const double delta_H_NN_init = 0.2E3; +const double delta_S_NN_init = -5.7; +double T; // Kelvin +double energy_local(int s){ + /* + This energy includes the repulsive energy (100K) and the hybridization free energy for the matched patches, + allowing for single internal mismatches. -int moveStep(int s){ + The free energy is determined using the nearest-neighbor parametrization (pH 7), + taking into account terminal A-T penalties, + internal mismatches, + dangling ends, and + temperature and salt concentration dependence, + but do not consider loops or bulges. + + References: + 1. A. Reinhardt and D. Frenkel, Numerical Evidence for Nucleated Self-Assembly of DNA Brick Structures, Phys. Rev. Lett. 112, 238103 (2014) + 2. J. SantaLucia, Jr. and D. Hicks, The Thermodynamics of DNA Structural Motifs, Annu. Rev. Biophys. Biomol. Struct. 33, 415 (2004) + */ + int i, j, k, nearests; + ppos npx; + + double E_repulsive; // Joules + nearests = 0; + for (i = -1; i <= 1; i += 2){ + for (j = -1; j <= 1; j += 2){ + for (k = -1; k <= 1; k += 2){ + npx = mol[s].px + ppos(i, j, k); + if (stage[npx.x][npx.y][npx.z] >= 0)nearests++; + } + } + } + E_repulsive = nearests*k_B*100; + + /* + For a given number of basepairs in a certain duplex, and a given salt concentration, + the free energy corrections by sodium dependence is constant, thus ignored when calculating energy differences. + */ + double E_patches_cal = 0; + for (i = -1; i <= 1; i += 2){ + for (j = -1; j <= 1; j += 2){ + for (k = -1; k <= 1; k += 2){ + npx = mol[s].px + ppos(i, j, k); + int s1 = stage[npx.x][npx.y][npx.z]; + if (s1 >= 0){ + int ornt0 = 4 * (i + 1) / 2 + 2 * (j + 1) / 2 + (k + 1) / 2; + int ornt1 = 7 - ornt0; + int n0ps = -1, n1ps = -1; // patch serial for the relative bonding. -1 if not exist. + n0ps = mol[s].findPatchSerial(ornt0); + n1ps = mol[s].findPatchSerial(ornt1); + if (n0ps >= 0 && n1ps >= 0 && couldPatchInteract[n0ps][n1ps]){ + int mismatches = 0, internalMismatches = 0; + int m; + for (m = 0; m < 8; m++){ + if (ntPair(mol[s].patch[n0ps][m]) != mol[s1].patch[n1ps][7 - m]){ + mismatches++; + if (m > 0 && m < 7)internalMismatches++; + } + } + switch (mismatches){ + case 0: + E_patches_cal += delta_H_NN_init - T*delta_S_NN_init; + for (m = 0; m < 7; m++){ + } + break; + case 1: + if (internalMismatches == 1){ + + } + } + } + } + } + } + } + + cout << E_repulsive << endl; + + + return 0; +} +int moveStep(int s){ + double E0 = energy_local(s); return 0; } int simulationProcess(){ int totalSteps = 10000; int step = 0; + T = 300; + + for (int i = 0; i < N; i++){ + cout << i << '\t'; + moveStep(i); + } return 0; } \ No newline at end of file diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_Simulation.h b/GraduateProject_DNASelfAssembling/GraduateProject_Simulation.h index d8d4485..4b35cea 100644 --- a/GraduateProject_DNASelfAssembling/GraduateProject_Simulation.h +++ b/GraduateProject_DNASelfAssembling/GraduateProject_Simulation.h @@ -1,4 +1,10 @@ #pragma once +#define k_B 1.381E-23 // SI units +#define N_A 6.023E23 // SI units + +#define cal2J 4.184 // thermochemical calorie + +extern double T; int simulationPrepare(); int simulationProcess(); \ No newline at end of file From 429d49ed4a13de68b865fd69d468fc59c3202fe2 Mon Sep 17 00:00:00 2001 From: drelatgithub Date: Fri, 22 May 2015 14:23:14 +0800 Subject: [PATCH 10/13] NN_dH_kcal 20150522 --- .../GraduateProject_DNASelfAssembling.vcxproj | 2 + ...eProject_DNASelfAssembling.vcxproj.filters | 6 +++ .../GraduateProject_Data.cpp | 31 ++++++++++++ .../GraduateProject_Data.h | 16 +++++++ .../GraduateProject_Simulation.cpp | 48 ++++++++++--------- GraduateProject_DNASelfAssembling/stdafx.h | 1 + 6 files changed, 82 insertions(+), 22 deletions(-) create mode 100644 GraduateProject_DNASelfAssembling/GraduateProject_Data.cpp create mode 100644 GraduateProject_DNASelfAssembling/GraduateProject_Data.h diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.vcxproj b/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.vcxproj index 2b6389e..3d077c7 100644 --- a/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.vcxproj +++ b/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.vcxproj @@ -79,6 +79,7 @@ + @@ -86,6 +87,7 @@ + diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.vcxproj.filters b/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.vcxproj.filters index 25f3fd9..15a4163 100644 --- a/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.vcxproj.filters +++ b/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.vcxproj.filters @@ -33,6 +33,9 @@ 澶存枃浠 + + 澶存枃浠 + @@ -50,5 +53,8 @@ 婧愭枃浠 + + 婧愭枃浠 + \ No newline at end of file diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_Data.cpp b/GraduateProject_DNASelfAssembling/GraduateProject_Data.cpp new file mode 100644 index 0000000..062f984 --- /dev/null +++ b/GraduateProject_DNASelfAssembling/GraduateProject_Data.cpp @@ -0,0 +1,31 @@ +#include"stdafx.h" + +const double NN_dH_kcal[4][4][4] = { + { // AX/TY + { 1.2, 2.3, -0.6, -7.6 }, + { 5.3, 0.0, -8.4, 0.7 }, + { -0.7, -7.8, -3.1, 1.0 }, + { -7.2, -1.2, -2.5, -2.7 } + }, + { // CX/GY + { -0.9, 1.9, -0.7, -8.5 }, + { 0.6, -1.5, -8.0, -0.8 }, + { -4.0, -10.6, -4.9, -4.1 }, + { -7.8, -1.5, -2.8, -5.0 } + }, + { // GX/CY + { -2.9, 5.2, -0.6, -8.2 }, + { -0.7, 3.6, -9.8, 2.3 }, + { 0.5, -8.0, -6.0, 3.3 }, + { -8.4, 5.2, -4.4, -2.2 } + }, + { // TX/AY + { 4.7, 3.4, 0.7, -7.2 }, + { 7.6, 6.1, -8.2, 1.2 }, + { 3.0, -8.5, 1.6, -0.1 }, + { -7.6, 1.0, -1.3, 0.2 } + } +}; +const double NN_dS_cal[4][4][4]; +const double NN_dH_init_kcal = 0.2; +const double NN_dS_init_cal = -5.7; \ No newline at end of file diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_Data.h b/GraduateProject_DNASelfAssembling/GraduateProject_Data.h new file mode 100644 index 0000000..a10fe82 --- /dev/null +++ b/GraduateProject_DNASelfAssembling/GraduateProject_Data.h @@ -0,0 +1,16 @@ +#pragma once + +extern const double NN_dH_kcal[4][4][4]; +extern const double NN_dS_cal[4][4][4]; +/* + NN_dH_kcal[a][b][c], NN_dS_cal[a][b][c] + + 5' --- a --- b --- 3' + | | + 3' --- a' --- c --- 5' + + where a' is the paired nucleotide of a. + If c = b' then the index [a][b][b'] and [b'][a'][a] must refer to the same value. +*/ +extern const double NN_dH_init_kcal; +extern const double NN_dS_init_cal; \ No newline at end of file diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_Simulation.cpp b/GraduateProject_DNASelfAssembling/GraduateProject_Simulation.cpp index a1bdf06..19dcee6 100644 --- a/GraduateProject_DNASelfAssembling/GraduateProject_Simulation.cpp +++ b/GraduateProject_DNASelfAssembling/GraduateProject_Simulation.cpp @@ -57,13 +57,37 @@ const double delta_H_NN_init = 0.2E3; const double delta_S_NN_init = -5.7; double T; // Kelvin +double energy_local_patch(int s, int n0ps, int s1, int n1ps){ + double E_patch_cal = 0; + int mismatches = 0, internalMismatches = 0; + int m; + for (m = 0; m < 8; m++){ + if (ntPair(mol[s].patch[n0ps][m]) != mol[s1].patch[n1ps][7 - m]){ + mismatches++; + if (m > 0 && m < 7)internalMismatches++; + } + } + switch (mismatches){ + case 0: + E_patch_cal += delta_H_NN_init - T*delta_S_NN_init; + for (m = 0; m < 7; m++){ + + } + break; + case 1: + if (internalMismatches == 1){ + + } + } + return E_patch_cal; +} double energy_local(int s){ /* This energy includes the repulsive energy (100K) and the hybridization free energy for the matched patches, allowing for single internal mismatches. The free energy is determined using the nearest-neighbor parametrization (pH 7), - taking into account terminal A-T penalties, + taking into account terminal A-T penalties (not applicable because the DNA brick would not allow for a duplex to end together), internal mismatches, dangling ends, and temperature and salt concentration dependence, @@ -105,26 +129,7 @@ double energy_local(int s){ n0ps = mol[s].findPatchSerial(ornt0); n1ps = mol[s].findPatchSerial(ornt1); if (n0ps >= 0 && n1ps >= 0 && couldPatchInteract[n0ps][n1ps]){ - int mismatches = 0, internalMismatches = 0; - int m; - for (m = 0; m < 8; m++){ - if (ntPair(mol[s].patch[n0ps][m]) != mol[s1].patch[n1ps][7 - m]){ - mismatches++; - if (m > 0 && m < 7)internalMismatches++; - } - } - switch (mismatches){ - case 0: - E_patches_cal += delta_H_NN_init - T*delta_S_NN_init; - for (m = 0; m < 7; m++){ - - } - break; - case 1: - if (internalMismatches == 1){ - - } - } + E_patches_cal += energy_local_patch(s, n0ps, s1, n1ps); } } } @@ -132,7 +137,6 @@ double energy_local(int s){ } cout << E_repulsive << endl; - return 0; } diff --git a/GraduateProject_DNASelfAssembling/stdafx.h b/GraduateProject_DNASelfAssembling/stdafx.h index 4c791d9..2016a7b 100644 --- a/GraduateProject_DNASelfAssembling/stdafx.h +++ b/GraduateProject_DNASelfAssembling/stdafx.h @@ -22,6 +22,7 @@ using namespace std; #include"GraduateProject_PositionAndOrientation.h" #include"GraduateProject_PatchesAndPresets.h" #include"GraduateProject_Simulation.h" +#include"GraduateProject_Data.h" extern mt19937 gen; \ No newline at end of file From 551863e8624ceb26608d530e8337f39675ff25e7 Mon Sep 17 00:00:00 2001 From: drelatgithub Date: Fri, 22 May 2015 15:41:19 +0800 Subject: [PATCH 11/13] NN_dS_cal 20150522 --- .../GraduateProject_DNASelfAssembling.cpp | 13 +++++++ .../GraduateProject_Data.cpp | 39 ++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.cpp b/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.cpp index ce0a2bc..ad452d7 100644 --- a/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.cpp +++ b/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.cpp @@ -17,6 +17,19 @@ int _tmain(int argc, _TCHAR* argv[]) simulationPrepare(); simulationProcess(); + double check[4][4][4]; + int i, j, k; + double T37 = 273.15 + 37; + for (i = 0; i < 4; i++){ + for (j = 0; j < 4; j++){ + for (k = 0; k < 4; k++){ + check[i][j][k] = NN_dH_kcal[i][j][k] - T37*NN_dS_cal[i][j][k] / 1000; + cout << " \t" << check[i][j][k]; + } + cout << endl; + } + } + return 0; } diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_Data.cpp b/GraduateProject_DNASelfAssembling/GraduateProject_Data.cpp index 062f984..3235e3a 100644 --- a/GraduateProject_DNASelfAssembling/GraduateProject_Data.cpp +++ b/GraduateProject_DNASelfAssembling/GraduateProject_Data.cpp @@ -26,6 +26,41 @@ const double NN_dH_kcal[4][4][4] = { { -7.6, 1.0, -1.3, 0.2 } } }; -const double NN_dS_cal[4][4][4]; +const double NN_dS_cal[4][4][4] = { + { // AX/TY + { 1.7, 4.6, -2.3, -21.3 }, + { 14.6, -4.4, -22.4, 0.2 }, + { -2.3, -21.0, -9.5, 0.9 }, + { -20.4, -6.2, -8.3, -10.8 } + }, + { // CX/GY + { -4.2, 3.7, -2.3, -22.7 }, + { -0.6, -7.2, -19.9, -4.5 }, + { -13.2, -27.2, -15.3, -11.7 }, + { -21.0, -6.1, -8.0, -15.8 } + }, + { // GX/CY + { -9.8, 14.2, -1.0, -22.2 }, + { -3.8, 8.9, -24.4, 5.4 }, + { 3.2, -19.9, -15.8, 10.4 }, + { -22.4, 13.5, -12.3, -8.4 } + }, + { // TX/AY + { 12.9, 8.0, 0.7, -21.3 }, + { 20.2, 16.4, -22.2, 0.7 }, + { 7.4, -22.7, 3.6, -1.7 }, + { -21.3, 0.7, -5.3, -1.5 } + } +}; const double NN_dH_init_kcal = 0.2; -const double NN_dS_init_cal = -5.7; \ No newline at end of file +const double NN_dS_init_cal = -5.7; +/* + References: + + 1. J. SantaLucia, Jr. and D. Hicks, The Thermodynamics of DNA Structural Motifs, Annu. Rev. Biophys. Biomol. Struct. 33, 415 (2004) + 2. Allawi HT, SantaLucia J Jr. Thermodynamics and NMR of internal G-T mismatches in DNA. Biochemistry 36:10581-94 (1997) + 3. Allawi HT, SantaLucia J Jr. Nearestneighbor thermodynamics of internal A-C mismatches in DNA: sequence dependence and pH effects. Biochemistry 37:9435-44 (1998) + 4. Allawi HT, SantaLucia J Jr. Nearestneighbor thermodynamics parameters for internal G-A mismatches in DNA. Biochemistry 37:2170-79 (1998) + 5. Allawi HT, SantaLucia J Jr. Thermodynamics of internal C-T mismatches in DNA. Nucleic Acids Res. 26:2694-701 (1998) + 6. Peyret N, Seneviratne PA, Allawi HT, SantaLucia J Jr. Nearest-neighbor thermodynamics and NMR of DNA sequences with internal A-A, C-C, G-G, and T-T mismatches. Biochemistry 38:3468-77 (1999) +*/ From 96909c923b748e2700f5aa2d9f346506eb0e2fc7 Mon Sep 17 00:00:00 2001 From: drelatgithub Date: Fri, 22 May 2015 21:02:17 +0800 Subject: [PATCH 12/13] DanglingEnds Data --- .../GraduateProject_DNASelfAssembling.cpp | 14 ---- .../GraduateProject_Data.cpp | 69 +++++++++++++++++++ .../GraduateProject_Data.h | 24 ++++++- .../GraduateProject_Simulation.cpp | 8 ++- 4 files changed, 97 insertions(+), 18 deletions(-) diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.cpp b/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.cpp index ad452d7..9b7f935 100644 --- a/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.cpp +++ b/GraduateProject_DNASelfAssembling/GraduateProject_DNASelfAssembling.cpp @@ -17,19 +17,5 @@ int _tmain(int argc, _TCHAR* argv[]) simulationPrepare(); simulationProcess(); - double check[4][4][4]; - int i, j, k; - double T37 = 273.15 + 37; - for (i = 0; i < 4; i++){ - for (j = 0; j < 4; j++){ - for (k = 0; k < 4; k++){ - check[i][j][k] = NN_dH_kcal[i][j][k] - T37*NN_dS_cal[i][j][k] / 1000; - cout << " \t" << check[i][j][k]; - } - cout << endl; - } - } - return 0; } - diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_Data.cpp b/GraduateProject_DNASelfAssembling/GraduateProject_Data.cpp index 3235e3a..0f367cf 100644 --- a/GraduateProject_DNASelfAssembling/GraduateProject_Data.cpp +++ b/GraduateProject_DNASelfAssembling/GraduateProject_Data.cpp @@ -52,8 +52,26 @@ const double NN_dS_cal[4][4][4] = { { -21.3, 0.7, -5.3, -1.5 } } }; +int NN_dG_check(){ + double check[4][4][4]; + int i, j, k; + double T37 = 273.15 + 37; + for (i = 0; i < 4; i++){ + for (j = 0; j < 4; j++){ + for (k = 0; k < 4; k++){ + check[i][j][k] = NN_dH_kcal[i][j][k] - T37*NN_dS_cal[i][j][k] / 1000; + cout << " \t" << check[i][j][k]; + } + cout << endl; + } + cout << endl; + } + return 0; +} const double NN_dH_init_kcal = 0.2; const double NN_dS_init_cal = -5.7; +const double NN_dH_ATPenalty_kcal = 2.2; +const double NN_dS_ATPenalty_cal = 6.9; /* References: @@ -64,3 +82,54 @@ const double NN_dS_init_cal = -5.7; 5. Allawi HT, SantaLucia J Jr. Thermodynamics of internal C-T mismatches in DNA. Nucleic Acids Res. 26:2694-701 (1998) 6. Peyret N, Seneviratne PA, Allawi HT, SantaLucia J Jr. Nearest-neighbor thermodynamics and NMR of DNA sequences with internal A-A, C-C, G-G, and T-T mismatches. Biochemistry 38:3468-77 (1999) */ + +extern const double NN_dH_DE_kcal[2][4][4] = { + { + { 0.2, 0.6, -1.1, -6.9 }, + { -6.3, -4.4, -5.1, -4.0 }, + { -3.7, -4.0, -3.9, -4.9 }, + { -2.9, -4.1, -4.2, -0.2 } + }, + { + { -0.5, 4.7, -4.1, -3.8 }, + { -5.9, -2.6, -3.2, -5.2 }, + { -2.1, -0.2, -3.9, -4.4 }, + { -0.7, 4.4, -1.6, 2.9 } + } +}; +extern const double NN_dS_DE_cal[2][4][4] = { + { + { 2.3, 3.3, -1.6, -20.0 }, + { -17.1, -12.6, -14.0, -10.9 }, + { -10.0, -11.9, -10.9, -13.8 }, + { -7.6, -13.0, -15.0, -0.5 } + }, + { + { -1.1, 14.2, -13.1, -12.6 }, + { -16.5, -7.4, -10.4, -15.0 }, + { -3.9, -0.1, -11.2, -13.1 }, + { -0.8, 14.9, -3.6, 10.4 } + } +}; +int NN_dG_DE_check(){ + double check[2][4][4]; + int i, j, k; + double T37 = 273.15 + 37; + for (i = 0; i < 2; i++){ + for (j = 0; j < 4; j++){ + for (k = 0; k < 4; k++){ + check[i][j][k] = NN_dH_DE_kcal[i][j][k] - T37*NN_dS_DE_cal[i][j][k] / 1000; + cout << " \t" << check[i][j][k]; + } + cout << endl; + } + cout << endl; + } + return 0; +} +/* + References: + + 1. J. SantaLucia, Jr. and D. Hicks, The Thermodynamics of DNA Structural Motifs, Annu. Rev. Biophys. Biomol. Struct. 33, 415 (2004) + 2. Bommarito S, Peyret N, SantaLucia J Jr. Thermodynamic parameters for DNA sequences with dangling ends. Nucleic Acids Res. 28:1929-34 (2000) +*/ diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_Data.h b/GraduateProject_DNASelfAssembling/GraduateProject_Data.h index a10fe82..27fc1b8 100644 --- a/GraduateProject_DNASelfAssembling/GraduateProject_Data.h +++ b/GraduateProject_DNASelfAssembling/GraduateProject_Data.h @@ -12,5 +12,27 @@ extern const double NN_dS_cal[4][4][4]; where a' is the paired nucleotide of a. If c = b' then the index [a][b][b'] and [b'][a'][a] must refer to the same value. */ +//int NN_dG_check(); extern const double NN_dH_init_kcal; -extern const double NN_dS_init_cal; \ No newline at end of file +extern const double NN_dS_init_cal; +extern const double NN_dH_ATPenalty_kcal; +extern const double NN_dS_ATPenalty_cal; + +extern const double NN_dH_DE_kcal[2][4][4]; +extern const double NN_dS_DE_cal[2][4][4]; +/* + NN_dH_DE_kcal[0,1][a][b], NN_dS_DE_cal[0,1][a][b] + + 0 mode: 5' dangling ends + + 5' --- b --- a --- 3' + | + a' --- 5' + + 1 mode: 3' dangling ends + + a' --- 3' + | + 3' --- b --- a --- 5' +*/ +//int NN_dG_DE_check(); diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_Simulation.cpp b/GraduateProject_DNASelfAssembling/GraduateProject_Simulation.cpp index 19dcee6..c704e0d 100644 --- a/GraduateProject_DNASelfAssembling/GraduateProject_Simulation.cpp +++ b/GraduateProject_DNASelfAssembling/GraduateProject_Simulation.cpp @@ -87,7 +87,7 @@ double energy_local(int s){ allowing for single internal mismatches. The free energy is determined using the nearest-neighbor parametrization (pH 7), - taking into account terminal A-T penalties (not applicable because the DNA brick would not allow for a duplex to end together), + taking into account terminal A-T penalties, internal mismatches, dangling ends, and temperature and salt concentration dependence, @@ -113,8 +113,10 @@ double energy_local(int s){ E_repulsive = nearests*k_B*100; /* - For a given number of basepairs in a certain duplex, and a given salt concentration, - the free energy corrections by sodium dependence is constant, thus ignored when calculating energy differences. + 1. For a given number of basepairs in a certain duplex, and a given salt concentration, + the free energy corrections by sodium dependence is constant, thus ignored when calculating energy differences. + 2. The initiation energy is not applicable because the DNA brick would not allow for a duplex to start together. + 3. The terminal A-T penalty is not applicable because the DNA brick would not allow for a duplex to end together. */ double E_patches_cal = 0; for (i = -1; i <= 1; i += 2){ From 3332e095a86aa8ca232c22ee10a68fc97100a04c Mon Sep 17 00:00:00 2001 From: drelatgithub Date: Sat, 23 May 2015 01:41:55 +0800 Subject: [PATCH 13/13] 20150522 daily --- .../GraduateProject_Simulation.cpp | 120 +++++++++++++++--- .../GraduateProject_Simulation.h | 4 +- 2 files changed, 105 insertions(+), 19 deletions(-) diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_Simulation.cpp b/GraduateProject_DNASelfAssembling/GraduateProject_Simulation.cpp index c704e0d..99ce34d 100644 --- a/GraduateProject_DNASelfAssembling/GraduateProject_Simulation.cpp +++ b/GraduateProject_DNASelfAssembling/GraduateProject_Simulation.cpp @@ -15,6 +15,9 @@ bool couldPlaceMolecule(int x, int y, int z){ } return true; } +bool couldPlaceMolecule(ppos px){ + return couldPlaceMolecule(px.x, px.y, px.z); +} int simulationPrepare(){ /* The following algorithm used has LOW efficiency, and needs to be improved. @@ -53,33 +56,48 @@ int simulationPrepare(){ return 0; } -const double delta_H_NN_init = 0.2E3; -const double delta_S_NN_init = -5.7; double T; // Kelvin double energy_local_patch(int s, int n0ps, int s1, int n1ps){ - double E_patch_cal = 0; + double E_patch_kcal = 0; int mismatches = 0, internalMismatches = 0; int m; + int a, b, c; for (m = 0; m < 8; m++){ if (ntPair(mol[s].patch[n0ps][m]) != mol[s1].patch[n1ps][7 - m]){ mismatches++; if (m > 0 && m < 7)internalMismatches++; } } + int s53 = isPatchConsequent[n0ps] ? s : s1, ps53 = isPatchConsequent[n0ps] ? n0ps : n1ps; + int s35 = isPatchConsequent[n0ps] ? s1 : s, ps35 = isPatchConsequent[n0ps] ? n1ps : n0ps; switch (mismatches){ case 0: - E_patch_cal += delta_H_NN_init - T*delta_S_NN_init; for (m = 0; m < 7; m++){ - + a = ntSerial(mol[s53].patch[ps53][m]); + b = ntSerial(mol[s53].patch[ps53][m + 1]); + c = ntSerial(mol[s35].patch[ps35][6 - m]); + E_patch_kcal += NN_dH_kcal[a][b][c] - T*NN_dS_cal[a][b][c] / 1000; } break; case 1: if (internalMismatches == 1){ - + for (m = 0; m < 7; m++){ + a = ntSerial(mol[s53].patch[ps53][m]); + b = ntSerial(mol[s53].patch[ps53][m + 1]); + c = ntSerial(mol[s35].patch[ps35][6 - m]); + E_patch_kcal += NN_dH_kcal[a][b][c] - T*NN_dS_cal[a][b][c] / 1000; + if (ntPair(b) != c){ + a = ntSerial(mol[s35].patch[ps35][5 - m]); + b = ntSerial(mol[s35].patch[ps35][6 - m]); + c = ntSerial(mol[s53].patch[ps53][m + 1]); + E_patch_kcal += NN_dH_kcal[a][b][c] - T*NN_dS_cal[a][b][c] / 1000; + m++; + } + } } } - return E_patch_cal; + return E_patch_kcal; } double energy_local(int s){ /* @@ -118,7 +136,7 @@ double energy_local(int s){ 2. The initiation energy is not applicable because the DNA brick would not allow for a duplex to start together. 3. The terminal A-T penalty is not applicable because the DNA brick would not allow for a duplex to end together. */ - double E_patches_cal = 0; + double E_patches_kcal = 0; // 1000 calories per mol for (i = -1; i <= 1; i += 2){ for (j = -1; j <= 1; j += 2){ for (k = -1; k <= 1; k += 2){ @@ -129,32 +147,98 @@ double energy_local(int s){ int ornt1 = 7 - ornt0; int n0ps = -1, n1ps = -1; // patch serial for the relative bonding. -1 if not exist. n0ps = mol[s].findPatchSerial(ornt0); - n1ps = mol[s].findPatchSerial(ornt1); + n1ps = mol[s1].findPatchSerial(ornt1); if (n0ps >= 0 && n1ps >= 0 && couldPatchInteract[n0ps][n1ps]){ - E_patches_cal += energy_local_patch(s, n0ps, s1, n1ps); + E_patches_kcal += energy_local_patch(s, n0ps, s1, n1ps); } } } } } - cout << E_repulsive << endl; - - return 0; + double E_total = E_repulsive + E_patches_kcal * 1000 * cal2J / N_A; + return E_total; } int moveStep(int s){ double E0 = energy_local(s); + static uniform_int_distribution<> translateOrRotate(0, 1); + static uniform_int_distribution<> anotherOrnt(0, 22); // only 23 possible orientations in order to exclude the original orientation + static uniform_int_distribution<> anotherCoor(-1, 1); + static uniform_real_distribution<> judge(0, 1); // Metropolis Criterion + if (translateOrRotate(gen)){ + int oOrnt = mol[s].ornt; + int nOrnt = anotherOrnt(gen); + nOrnt = (nOrnt >= oOrnt) ? (nOrnt + 1) : nOrnt; + mol[s].ornt = nOrnt; + double E1 = energy_local(s); + if (E1 > E0 && judge(gen) > exp(-(E1 - E0) / k_B / T)){ + mol[s].ornt = oOrnt; + } + } + else{ + ppos opx = mol[s].px; + ppos npx = opx + ppos(anotherCoor(gen), anotherCoor(gen), anotherCoor(gen)); + if (stage[npx.x][npx.y][npx.z] == -1){ + mol[s].px = npx; + stage[opx.x][opx.y][opx.z] = -1; + stage[npx.x][npx.y][npx.z] = s; + double E1 = energy_local(s); + if (E1 > E0 && judge(gen) > exp(-(E1 - E0) / k_B / T)){ + mol[s].px = opx; + stage[opx.x][opx.y][opx.z] = s; + stage[npx.x][npx.y][npx.z] = -1; + } + } + } return 0; } int simulationProcess(){ int totalSteps = 10000; - int step = 0; - T = 300; + int step; + T = 315; - for (int i = 0; i < N; i++){ - cout << i << '\t'; - moveStep(i); + for (step = 0; step < 200000; step++){ + if (step % 1000 == 999)cout << step + 1 << '\t' << maxCorrectSize() << endl; + for (int i = 0; i < N; i++){ + moveStep(i); + } } return 0; +} + +int anotherMoleculeCombined(int *mark, int previousSerial){ + int ok = 1; + mark[previousSerial] = 1; + for (int i = 0; i < 4; i++){ + if (mol[previousSerial].correctbond[i] >= 0 && !mark[mol[previousSerial].correctbond[i]]){ + // do not derive the difference of ppos because it would render no negative offsets + int dx = mol[mol[previousSerial].correctbond[i]].px.x - mol[previousSerial].px.x; + int dy = mol[mol[previousSerial].correctbond[i]].px.y - mol[previousSerial].px.y; + int dz = mol[mol[previousSerial].correctbond[i]].px.z - mol[previousSerial].px.z; + if (abs(dx) == 1 && abs(dy) == 1 && abs(dz) == 1){ + ok += anotherMoleculeCombined(mark, mol[previousSerial].correctbond[i]); + } + } + } + return ok; +} +int maxCorrectSize(){ + int *mark = new int[N]; + int max = 0, temp; + int p; + for (p = 0; p < N; p++){ + mark[p] = 0; + } + p = 0; + while (p < N){ + if (!mark[p]){ + temp = anotherMoleculeCombined(mark, p); + if (max < temp)max = temp; + } + p++; + } + + delete[]mark; + return max; } \ No newline at end of file diff --git a/GraduateProject_DNASelfAssembling/GraduateProject_Simulation.h b/GraduateProject_DNASelfAssembling/GraduateProject_Simulation.h index 4b35cea..076386f 100644 --- a/GraduateProject_DNASelfAssembling/GraduateProject_Simulation.h +++ b/GraduateProject_DNASelfAssembling/GraduateProject_Simulation.h @@ -7,4 +7,6 @@ extern double T; int simulationPrepare(); -int simulationProcess(); \ No newline at end of file +int simulationProcess(); + +int maxCorrectSize();