Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Scientific Software
Takin
mag-core
Commits
b7db68d0
Commit
b7db68d0
authored
Dec 06, 2019
by
Tobias WEBER
Browse files
added B matrix to moldyn tool
parent
8f74cbe7
Changes
3
Hide whitespace changes
Inline
Side-by-side
tools/moldyn/moldyn-loader.h
View file @
b7db68d0
...
...
@@ -14,6 +14,7 @@
#include <vector>
#include <string>
#include "libs/file.h"
#include "libs/str.h"
...
...
@@ -86,6 +87,22 @@ class MolDyn
}
const
t_vec
&
GetBaseA
()
const
{
return
m_baseA
;
}
const
t_vec
&
GetBaseB
()
const
{
return
m_baseB
;
}
const
t_vec
&
GetBaseC
()
const
{
return
m_baseC
;
}
std
::
size_t
GetFrameCount
()
const
{
return
m_frames
.
size
();
}
const
MolFrame
<
t_real
,
t_vec
>&
GetFrame
(
std
::
size_t
frame
)
const
{
return
m_frames
[
frame
];
}
const
std
::
string
&
GetAtomName
(
std
::
size_t
idx
)
const
{
return
m_vecAtoms
[
idx
];
}
void
AddAtomType
(
const
std
::
string
&
name
,
unsigned
int
number
)
{
m_vecAtoms
.
push_back
(
name
);
...
...
@@ -120,6 +137,9 @@ class MolDyn
Clear
();
std
::
size_t
filesize
=
tl2
::
get_file_size
(
ifstr
);
std
::
cout
<<
"File size: "
<<
filesize
/
1024
/
1024
<<
" MB."
<<
std
::
endl
;
std
::
string
strSys
;
std
::
getline
(
ifstr
,
strSys
);
tl2
::
trim
(
strSys
);
...
...
@@ -179,6 +199,7 @@ class MolDyn
std
::
size_t
iNumConfigs
=
0
;
t_real
percentage
=
0
;
while
(
true
)
{
std
::
string
strConfig
;
...
...
@@ -190,7 +211,8 @@ class MolDyn
if
(
frameskip
||
iNumConfigs
%
100
)
{
std
::
cout
<<
"
\r
Reading "
<<
strConfig
<<
"..."
<<
" "
;
std
::
cout
<<
"
\r
Reading "
<<
strConfig
<<
". "
<<
unsigned
{
percentage
}
<<
" %. "
;
std
::
cout
.
flush
();
}
...
...
@@ -244,9 +266,13 @@ class MolDyn
std
::
getline
(
ifstr
,
strTmp
);
}
}
}
std
::
cout
<<
"
\r
Read "
<<
iNumConfigs
<<
" configurations."
<<
" "
<<
std
::
endl
;
std
::
size_t
filepos
=
tl2
::
get_file_pos
(
ifstr
);
percentage
=
t_real
{
filepos
*
100
}
/
t_real
{
filesize
};
}
std
::
cout
<<
"
\r
Read "
<<
iNumConfigs
<<
" configurations. "
<<
" "
<<
std
::
endl
;
return
1
;
}
...
...
@@ -259,23 +285,6 @@ class MolDyn
}
std
::
size_t
GetFrameCount
()
const
{
return
m_frames
.
size
();
}
const
MolFrame
<
t_real
,
t_vec
>&
GetFrame
(
std
::
size_t
frame
)
const
{
return
m_frames
[
frame
];
}
const
std
::
string
&
GetAtomName
(
std
::
size_t
idx
)
const
{
return
m_vecAtoms
[
idx
];
}
private:
t_vec
m_baseA
;
t_vec
m_baseB
;
...
...
tools/moldyn/moldyn.cpp
View file @
b7db68d0
...
...
@@ -12,6 +12,7 @@
#include <QtWidgets/QFileDialog>
#include <QtWidgets/QLabel>
#include <QtWidgets/QSpinBox>
#include <QtWidgets/QComboBox>
#include <QtWidgets/QMessageBox>
#include <iostream>
...
...
@@ -43,8 +44,8 @@ class MolDynFileDlg : public QFileDialog
QLabel
*
labelFrameSkip
=
new
QLabel
(
"Frame Skip: "
,
this
);
m_spinFrameSkip
=
new
QSpinBox
(
this
);
m_spinFrameSkip
->
setValue
(
10
);
m_spinFrameSkip
->
set
M
in
imum
(
0
);
m_spinFrameSkip
->
set
Maximum
(
9999999
);
m_spinFrameSkip
->
set
S
in
gleStep
(
1
);
m_spinFrameSkip
->
set
Range
(
0
,
9999999
);
labelFrameSkip
->
setSizePolicy
(
QSizePolicy
{
QSizePolicy
::
Fixed
,
QSizePolicy
::
Fixed
});
m_spinFrameSkip
->
setSizePolicy
(
QSizePolicy
{
QSizePolicy
::
Expanding
,
QSizePolicy
::
Fixed
});
...
...
@@ -142,22 +143,59 @@ MolDynDlg::MolDynDlg(QWidget* pParent) : QMainWindow{pParent},
connect
(
m_plot
,
&
GlPlot
::
MouseUp
,
this
,
&
MolDynDlg
::
PlotMouseUp
);
//this->setCentralWidget(m_plot);
pMainGrid
->
addWidget
(
m_plot
,
0
,
0
,
1
,
1
);
pMainGrid
->
addWidget
(
m_plot
,
0
,
0
,
1
,
9
);
}
// controls
{
auto
labCoordSys
=
new
QLabel
(
"Coordinates:"
,
this
);
auto
labFrames
=
new
QLabel
(
"Frames:"
,
this
);
auto
labScale
=
new
QLabel
(
"Scale:"
,
this
);
labCoordSys
->
setSizePolicy
(
QSizePolicy
{
QSizePolicy
::
Fixed
,
QSizePolicy
::
Fixed
});
labFrames
->
setSizePolicy
(
QSizePolicy
{
QSizePolicy
::
Fixed
,
QSizePolicy
::
Fixed
});
labScale
->
setSizePolicy
(
QSizePolicy
{
QSizePolicy
::
Fixed
,
QSizePolicy
::
Fixed
});
auto
comboCoordSys
=
new
QComboBox
(
this
);
comboCoordSys
->
addItem
(
"Fractional Units (rlu)"
);
comboCoordSys
->
addItem
(
"Lab Units (A)"
);
comboCoordSys
->
setFocusPolicy
(
Qt
::
StrongFocus
);
m_spinScale
=
new
QDoubleSpinBox
(
this
);
m_spinScale
->
setDecimals
(
4
);
m_spinScale
->
setRange
(
1e-4
,
1e4
);
m_spinScale
->
setSingleStep
(
0.1
);
m_spinScale
->
setValue
(
0.4
);
m_spinScale
->
setFocusPolicy
(
Qt
::
StrongFocus
);
m_slider
=
new
QSlider
(
Qt
::
Horizontal
,
this
);
m_slider
->
setSizePolicy
(
QSizePolicy
{
QSizePolicy
::
Expanding
,
QSizePolicy
::
Minimum
});
m_slider
->
setMinimum
(
0
);
m_slider
->
setSingleStep
(
1
);
m_slider
->
setPageStep
(
10
);
m_slider
->
setTracking
(
1
);
m_slider
->
setFocusPolicy
(
Qt
::
StrongFocus
);
connect
(
m_slider
,
&
QSlider
::
valueChanged
,
this
,
&
MolDynDlg
::
SliderValueChanged
);
pMainGrid
->
addWidget
(
m_slider
,
1
,
0
,
1
,
1
);
connect
(
comboCoordSys
,
static_cast
<
void
(
QComboBox
::*
)(
int
)
>
(
&
QComboBox
::
currentIndexChanged
),
this
,
[
this
](
int
val
)
{
if
(
this
->
m_plot
)
this
->
m_plot
->
GetImpl
()
->
SetCoordSys
(
val
);
});
connect
(
m_spinScale
,
static_cast
<
void
(
QDoubleSpinBox
::*
)(
double
)
>
(
&
QDoubleSpinBox
::
valueChanged
),
this
,
[
this
](
double
val
)
{
if
(
!
this
->
m_plot
)
return
;
// hack to trigger update
SliderValueChanged
(
m_slider
->
value
());
});
pMainGrid
->
addWidget
(
labCoordSys
,
1
,
0
,
1
,
1
);
pMainGrid
->
addWidget
(
comboCoordSys
,
1
,
1
,
1
,
1
);
pMainGrid
->
addWidget
(
labScale
,
1
,
2
,
1
,
1
);
pMainGrid
->
addWidget
(
m_spinScale
,
1
,
3
,
1
,
1
);
pMainGrid
->
addWidget
(
labFrames
,
1
,
4
,
1
,
1
);
pMainGrid
->
addWidget
(
m_slider
,
1
,
5
,
1
,
4
);
}
...
...
@@ -189,10 +227,13 @@ std::size_t MolDynDlg::Add3DItem(const t_vec& vec, const t_vec& col, t_real scal
*/
void
MolDynDlg
::
Change3DItem
(
std
::
size_t
obj
,
const
t_vec
*
vec
,
const
t_vec
*
col
,
const
t_real
*
scale
,
const
std
::
string
*
label
)
{
t_mat_gl
mat
=
m
::
hom_translation
<
t_mat_gl
>
((
*
vec
)[
0
],
(
*
vec
)[
1
],
(
*
vec
)[
2
]);
if
(
scale
)
mat
*=
m
::
hom_scaling
<
t_mat_gl
>
(
*
scale
,
*
scale
,
*
scale
);
if
(
vec
)
{
t_mat_gl
mat
=
m
::
hom_translation
<
t_mat_gl
>
((
*
vec
)[
0
],
(
*
vec
)[
1
],
(
*
vec
)[
2
]);
if
(
scale
)
mat
*=
m
::
hom_scaling
<
t_mat_gl
>
(
*
scale
,
*
scale
,
*
scale
);
m_plot
->
GetImpl
()
->
SetObjectMatrix
(
obj
,
mat
);
}
m_plot
->
GetImpl
()
->
SetObjectMatrix
(
obj
,
mat
);
if
(
col
)
m_plot
->
GetImpl
()
->
SetObjectCol
(
obj
,
(
*
col
)[
0
],
(
*
col
)[
1
],
(
*
col
)[
2
],
1
);
if
(
label
)
m_plot
->
GetImpl
()
->
SetObjectLabel
(
obj
,
*
label
);
if
(
label
)
m_plot
->
GetImpl
()
->
SetObjectDataString
(
obj
,
*
label
);
...
...
@@ -246,6 +287,32 @@ void MolDynDlg::Load()
m_slider
->
setMaximum
(
m_mol
.
GetFrameCount
()
-
1
);
// crystal A and B matrices
const
t_vec
&
_a
=
m_mol
.
GetBaseA
();
const
t_vec
&
_b
=
m_mol
.
GetBaseB
();
const
t_vec
&
_c
=
m_mol
.
GetBaseC
();
m_crystA
=
m
::
create
<
t_mat
>
({
_a
[
0
],
_b
[
0
],
_c
[
0
],
_a
[
1
],
_b
[
1
],
_c
[
1
],
_a
[
2
],
_b
[
2
],
_c
[
2
]
});
bool
ok
=
true
;
std
::
tie
(
m_crystB
,
ok
)
=
m
::
inv
(
m_crystA
);
if
(
!
ok
)
{
m_crystB
=
m
::
unit
<
t_mat
>
();
QMessageBox
::
critical
(
this
,
"Molecular Dynamics"
,
"Error: Cannot invert A matrix."
);
}
m_crystB
/=
t_real_gl
(
2
)
*
m
::
pi
<
t_real_gl
>
;
t_mat_gl
matA
{
m_crystA
};
m_plot
->
GetImpl
()
->
SetBTrafo
(
m_crystB
,
&
matA
);
std
::
cout
<<
"A matrix: "
<<
m_crystA
<<
",
\n
"
<<
"B matrix: "
<<
m_crystB
<<
"."
<<
std
::
endl
;
// atom colors
std
::
vector
<
t_vec
>
cols
=
{
...
...
@@ -268,7 +335,8 @@ void MolDynDlg::Load()
const
auto
&
coords
=
frame
.
GetCoords
(
atomidx
);
for
(
const
t_vec
&
vec
:
coords
)
{
std
::
size_t
handle
=
Add3DItem
(
vec
,
cols
[
atomidx
%
cols
.
size
()],
m_atomscale
,
m_mol
.
GetAtomName
(
atomidx
));
t_real
atomscale
=
m_spinScale
->
value
();
std
::
size_t
handle
=
Add3DItem
(
vec
,
cols
[
atomidx
%
cols
.
size
()],
atomscale
,
m_mol
.
GetAtomName
(
atomidx
));
m_sphereHandles
.
push_back
(
handle
);
}
}
...
...
@@ -364,6 +432,7 @@ void MolDynDlg::SliderValueChanged(int val)
// update atom position with selected frame
const
auto
&
frame
=
m_mol
.
GetFrame
(
val
);
t_real
atomscale
=
m_spinScale
->
value
();
std
::
size_t
counter
=
0
;
for
(
std
::
size_t
atomidx
=
0
;
atomidx
<
frame
.
GetNumAtoms
();
++
atomidx
)
...
...
@@ -372,7 +441,7 @@ void MolDynDlg::SliderValueChanged(int val)
for
(
const
t_vec
&
vec
:
coords
)
{
std
::
size_t
obj
=
m_sphereHandles
[
counter
];
Change3DItem
(
obj
,
&
vec
,
nullptr
,
&
m_
atomscale
);
Change3DItem
(
obj
,
&
vec
,
nullptr
,
&
atomscale
);
++
counter
;
}
...
...
@@ -392,6 +461,9 @@ void MolDynDlg::AfterGLInitialisation()
m_sphere
=
m_plot
->
GetImpl
()
->
AddSphere
(
0.05
,
0.
,
0.
,
0.
,
1.
,
1.
,
1.
,
1.
);
m_plot
->
GetImpl
()
->
SetObjectVisible
(
m_sphere
,
false
);
// B matrix
m_plot
->
GetImpl
()
->
SetBTrafo
(
m_crystB
);
// GL device info
auto
[
strGlVer
,
strGlShaderVer
,
strGlVendor
,
strGlRenderer
]
=
m_plot
->
GetImpl
()
->
GetGlDescr
();
...
...
tools/moldyn/moldyn.h
View file @
b7db68d0
...
...
@@ -13,6 +13,7 @@
#include <QtWidgets/QMenuBar>
#include <QtWidgets/QStatusBar>
#include <QtWidgets/QSlider>
#include <QtWidgets/QDoubleSpinBox>
#include <QtCore/QSettings>
#include <vector>
...
...
@@ -57,11 +58,14 @@ protected:
protected:
MolDyn
<
t_real
,
t_vec
>
m_mol
;
t_mat
m_crystA
=
m
::
unit
<
t_mat
>
(
3
);
t_mat
m_crystB
=
m
::
unit
<
t_mat
>
(
3
);
QSettings
*
m_sett
=
nullptr
;
QMenuBar
*
m_menu
=
nullptr
;
QStatusBar
*
m_status
=
nullptr
;
QSlider
*
m_slider
=
nullptr
;
QDoubleSpinBox
*
m_spinScale
=
nullptr
;
GlPlot
*
m_plot
=
nullptr
;
std
::
size_t
m_sphere
=
0
;
...
...
@@ -71,8 +75,6 @@ protected:
private:
long
m_curPickedObj
=
-
1
;
bool
m_ignoreChanges
=
1
;
t_real
m_atomscale
=
0.4
;
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment