Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#MDANSE : Molecular Dynamics Analysis for Neutron Scattering Experiments
#------------------------------------------------------------------------------------------
#Copyright (C)
#2015- Eric C. Pellegrini Institut Laue-Langevin
#BP 156
#6, rue Jules Horowitz
#38042 Grenoble Cedex 9
#France
#pellegrini[at]ill.fr
#goret[at]ill.fr
#aoun[at]ill.fr
#
#This library is free software; you can redistribute it and/or
#modify it under the terms of the GNU Lesser General Public
#License as published by the Free Software Foundation; either
#version 2.1 of the License, or (at your option) any later version.
#
#This library is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
#Lesser General Public License for more details.
#
#You should have received a copy of the GNU Lesser General Public
#License along with this library; if not, write to the Free Software
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
'''
Created on Jul 2, 2015
:author: Eric C. Pellegrini
'''
import operator
import os
import wx
import wx.aui as wxaui
import wx.grid as wxgrid
from MDANSE import LOGGER
from MDANSE.Framework.Widgets.UserDefinitionWidget import UserDefinitionPlugin
class PartialChargesPlugin(UserDefinitionPlugin):
type = 'partial_charges'
label = "Partial charges"
ancestor = ["molecular_viewer"]
def __init__(self, parent, *args, **kwargs):
self._parent = parent
self._selectedAtoms = []
UserDefinitionPlugin.__init__(self, parent)
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
def build_panel(self):
self._mainPanel = wx.Panel(self,wx.ID_ANY)
sizer = wx.BoxSizer(wx.VERTICAL)
self._grid = wxgrid.Grid(self._mainPanel)
sizer.Add(self._grid, 1, wx.ALL|wx.EXPAND, 5)
self._mainPanel.SetSizer(sizer)
self._mgr.AddPane(self._mainPanel, wxaui.AuiPaneInfo().DestroyOnClose().Center().Dock().CaptionVisible(False).CloseButton(False).BestSize(self.GetSize()))
self._mgr.Update()
def plug(self):
self.parent.mgr.GetPane(self).Float().Dockable(False).CloseButton(True).BestSize((600,600))
self.parent.mgr.Update()
self.set_trajectory(self.dataproxy.data)
def set_trajectory(self,trajectory):
self._trajectory = trajectory
self._target = os.path.basename(self._trajectory.filename)
self._grid.CreateGrid(self._trajectory.universe.numberOfAtoms(),3)
self._grid.SetRowLabelSize(1)
self._grid.SetColFormatNumber(0)
self._grid.SetColFormatNumber(1)
self._grid.SetColFormatNumber(2)
roAttr = wxgrid.GridCellAttr()
roAttr.SetReadOnly(True)
roAttr.SetBackgroundColour(wx.Colour(220,220,220))
self._grid.SetColAttr(0,roAttr)
self._grid.SetColAttr(1,roAttr)
floatAttr = wxgrid.GridCellAttr()
floatAttr.SetRenderer(wxgrid.GridCellFloatRenderer())
floatAttr.SetEditor(wxgrid.GridCellFloatEditor())
self._grid.SetColAttr(2,floatAttr)
self._grid.SetColLabelValue(0,'index')
self._grid.SetColLabelValue(1,'name')
self._grid.SetColLabelValue(2,'charge')
atoms = sorted(self._trajectory.universe.atomList(), key=operator.attrgetter('index'))
for idx, at in enumerate(atoms):
self._grid.SetCellValue(idx,0,str(idx))
self._grid.SetCellValue(idx,1,at.name)
def validate(self):
charges = {}
for i in range(self._trajectory.universe.numberOfAtoms()):
val = self._grid.GetCellValue(i,2)
if val:
charges[i] = float(val)
if not charges:
LOGGER("No partial charges defined.", "error", ["dialog"])
return None
return {'charges' : charges}