²é¿´: 730  |  »Ø¸´: 2

zyj8119

ľ³æ (ÖøÃûдÊÖ)

[½»Á÷] ¡¾Ô­´´¡¿MAPSÖй¹Öþ³¬¾§°ûµÄpython³ÌÐò ÒÑÓÐ2È˲ÎÓë

CODE:
#!/usr/bin/python
###########################################################################
#                   buildCluster.py  -  description
#                   -------------------------------
#   begin                : Fri Dec 15 16:11:04 CET 2006
#   copyright            : (C) 2006 by Scienomics
#   email                : Joerg-Ruediger.Hill@scienomics.com
###########################################################################
#
###########################################################################
#                                                                         #
#   This program and all subroutines,  data, and  files used by it are    #
#   protected by copyright and hence may not be used, copied, modified    #
#   transmitted, inspected, or executed by any means including the use    #
#   of electronic data processing equipment,  xerography, or any other    #
#   methods  without the express  written permission  of the copyright    #
#   holder.                                                               #
#                                                                         #
#   Copyright (C) 2006 Scienomics S. A.                                   #
#                                                                         #
###########################################################################
#
# $Id: buildCluster.py,v 1.10 2010/03/29 15:15:56 jrh Exp $
# $Log: buildCluster.py,v $
# Revision 1.10  2010/03/29 15:15:56  jrh
# Moved to new way of retrieving plugin objects
#
# Revision 1.9  2008/10/20 09:25:06  lperi
# Clear undo stack (bug 2562).
#
# Revision 1.8  2008/10/14 15:21:17  jrh
# Fixed bug 2520
#
# Revision 1.7  2008/01/16 12:21:18  jrh
# Moved to Qt4
#
# Revision 1.6  2007/01/16 10:28:26  jrh
# Removed automatic creation of cell since this might crash
#
# Revision 1.5  2006/12/15 16:07:31  jrh
# Added header and documentation
#
#

import Maps
import MapsChemistryDataModel
import MapsViewer
from PyQt4 import *

class ClusterBuilder:
  """ This class implements a cluster generating algorithm
      by cutting atoms from a periodic system based on a
      distance criterion. The class takes either the active
      molecule or asks the user to load a molecule if no
      active molecule is found, puts a molecule into a box
      at density 1.0 if the system is not periodic already,
      and builds a cluster by copying all atoms which are
      within 5 Ang from the central atom to a new model.
  """

  app=Maps.MapsApp.getContainer()
  cdm=MapsChemistryDataModel.ChemistryDataModel.get()
  viewerPlugin=MapsViewer.ViewerPlugin.get()
  project=None
  molecule=None

  def loadMolecule(self):
    activeViewer=self.viewerPlugin.getActiveViewer()
    if activeViewer != None:
      self.molecule=activeViewer.getMolecule()
      projectName=self.cdm.findProjectNameForMolecule(self.molecule)
      self.project=self.cdm.findProjectByName(projectName)
      QtGui.qApp.processEvents()
      return(0)
    else:
      QtGui.QMessageBox.information(self.app, "Note", "Please load a molecule from the\nfollowing dialog.")
      # Load a molecule from an existing file
      dialog=self.app.fileDialog
      dialog.setFileMode(QtGui.QFileDialog.ExistingFile)
      dialog.setWindowTitle("Open file")
      filters=QtCore.QStringList()
      filters.append("All files (*)")
      dialog.setFilters(filters)
      dialog.selectFile("")
      if dialog.exec_(Maps.FileDialog.DATA) == QtGui.QDialog.Accepted:
        fileName=str(dialog.selectedFiles()[0])
        self.app.openDocumentFile(fileName, None, "")
        projects=self.cdm.getProjects()
        self.project=projects[0]
        molecules=self.project.getMolecules()
        self.molecule=molecules[0]
        self.viewerPlugin.start(self.molecule)
        QtGui.qApp.processEvents()
        return(0)
      else:
        return(1)

  def createSuperCell(self):
    # Create a 3 x 3 x 3 super cell. If the system is not periodic tell
    # the user and exit
    if not self.molecule.isPeriodic():
      QtGui.QMessageBox.information(self.app, "Note", "Please use a periodic system with this script.")
      return(0);
    else:
      cell=self.molecule.getActiveConformation().getUnitcell()
    cell.setDuplicate(3, 3, 3, 1)
    cell.makeSuperCell(1)
    QtGui.qApp.processEvents()
    return(1)

  def cutCluster(self):
    # Cut a cluster by finding the atom closest to the center of the
    # super cell and including all atoms at a distance of up to
    # 5.0 Ang from this atom
    center=self.molecule.calculateCenterOfGravity(self.molecule.atoms)
    min=100.0
    centerAtom=None
    for atom in self.molecule.atoms:
      pos=atom.getCoordinates()
      diff=pos-center
      if diff.abs() < min:
        min=diff.abs()
        centerAtom=atom
    viewer=self.viewerPlugin.getActiveViewer()
    # Clear the undo stack to prevent a discontinuity
    # in the recorded editing actions which could
    # cause a crash
    viewer.clearUndoStack()
    viewer.setSelectionMode(MapsViewer.Viewer.DISTANCE, 5.0)
    viewer.selectAtoms(centerAtom, 1)
    viewer.copy()
    # Create a new model in the same project and paste the cluster
    # in there
    cluster=MapsChemistryDataModel.Molecule(self.cdm)
    cluster.setName("Cluster")
    self.project.addMolecule(cluster)
    self.viewerPlugin.start(cluster)
    clusterViewer=self.viewerPlugin.getActiveViewer()
    clusterViewer.paste()
    clusterViewer.centerMolecule()
    clusterViewer.getMoleculeRenderer().setSelection(cluster.atoms, 0)
    QtGui.qApp.processEvents()

  def run(self):
    if not self.loadMolecule():
      if self.createSuperCell():
        self.cutCluster()

#-------------------------
if __name__ == '__main__':
  builder=ClusterBuilder()
  builder.run()

»Ø¸´´ËÂ¥

» ±¾ÌûÒÑ»ñµÃµÄºì»¨£¨×îÐÂ10¶ä£©

» ²ÂÄãϲ»¶

ºÃºÃѧϰ£¬ÌìÌìÏòÉÏ¡£
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû
ËÍÏÊ»¨Ò»¶ä
2Â¥2012-03-22 16:11:27
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

juwendy

Ìú³æ (ÕýʽдÊÖ)

¶¥Ò»¸ö£¬Ö§³ÖÂ¥Ö÷¡£
3Â¥2012-03-22 21:09:32
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû
Ïà¹Ø°æ¿éÌø×ª ÎÒÒª¶©ÔÄÂ¥Ö÷ zyj8119 µÄÖ÷Ìâ¸üÐÂ
×î¾ßÈËÆøÈÈÌûÍÆ¼ö [²é¿´È«²¿] ×÷Õß »Ø/¿´ ×îºó·¢±í
[»ù½ðÉêÇë] 5¸ö%2F£¬·Ç¹Ì¶¨¶Î22¸ö×Öĸ +8 jaasxulu 2026-07-15 9/450 2026-07-18 17:40 by dxcgbm
[»ù½ðÉêÇë] ÃæÉϵÄË®ºÜÉî +10 ²¼²¼ºÍÒ»¶þ 2026-07-18 15/750 2026-07-18 17:07 by 6543yes
[»ù½ðÉêÇë] ¹úÉç¿ÆÍ¨Ñ¶ÆÀÉó +3 DZˮ¹Ú¾ü123 2026-07-18 4/200 2026-07-18 16:29 by ×î°®±à×ë´Çµä
[»ù½ðÉêÇë] ÉúÃü¿ÚC13ÃæÉÏ»áÆÀʱ¼ä +7 luckinging 2026-07-14 11/550 2026-07-17 20:43 by ³æ²·1988
[½Ìʦ֮¼Ò] ÄÚÐÄØÑ·¦ +16 Ë®±ùÔÂÔÂÒ°Íà 2026-07-12 16/800 2026-07-17 19:25 by otani
[»ù½ðÉêÇë] ÉúÃü¿ÚÃæÉÏ»áÆÀ½áÊøÁËÂð´ó¼ÒÓÐÖªµÀ½á¹ûÂð£¿ÏÖÔÚ»¹Ã»Óнá¹ûÕý³£²»£¿ +6 ±ÌË®00 2026-07-16 9/450 2026-07-17 15:21 by jaasxulu
[ÂÛÎÄͶ¸å] ͶӢÎÄÆÚ¿¯ÈçºÎ²éÖØ 10+5 ²»ÖªµÀȡʲôÃû× 2026-07-15 6/300 2026-07-17 09:07 by bobvan
[»ù½ðÉêÇë] ²»ÒªÔÙÊý¹ú×ÔÈ»ÉêÇëÊéµÄ filecode µÄ·Ö¸ô·û¸öÊýÁË +14 sadpencil 2026-07-12 21/1050 2026-07-17 00:15 by wangze12014
[Óлú½»Á÷] ²®°·Éϼ׻ùÇóÖú 100+4 002tmumu 2026-07-14 7/350 2026-07-16 19:47 by 002tmumu
[ÂÛÎÄͶ¸å] ¿ç³ö°æÉçÉÌͶ¸å 20+5 ÄߺÃ520 2026-07-13 5/250 2026-07-16 17:24 by ÎÞÊÓ¾üÍÅ
[»ù½ðÉêÇë] ÉúÉúÃüѧ²¿»áÆÀ +4 wuke100666 2026-07-15 4/200 2026-07-16 00:12 by À²À²Ð¡ÄÝ×Ó
[»ù½ðÉêÇë] H¿Ú£¬ÃæÉÏ£¬Ê±¼ä´Á7ÔÂ7ÈÕ¡£ +3 plumage5 2026-07-15 3/150 2026-07-15 21:06 by 6543yes
[»ù½ðÉêÇë] Сľ³æÃ»ÂäÁË£¬³ýÁËÆíµ»Ìû×Ó£¬¼¸ºõ¿´²»µ½ÓмÛÖµµÄÌû×Ó +13 botar 2026-07-14 14/700 2026-07-15 19:28 by º®Á÷32
[»ù½ðÉêÇë] »áÆÀ +5 ÎÞÃûÕßµÇɽ 2026-07-15 5/250 2026-07-15 18:15 by ¸Ü¾ÍÊÇÄã¶Ô
[»ù½ðÉêÇë] E¿Ú»áÆÀ +11 ²¼²¼ºÍÒ»¶þ 2026-07-13 13/650 2026-07-15 16:34 by Kittylucky
[»ù½ðÉêÇë] E¿ÚÇàC»áÆÀ½áÊøÁËÂ𣿠40+3 ССÊ鳿c 2026-07-14 9/450 2026-07-15 16:04 by °²¾²µÄÖªÁË
[ÂÛÎÄͶ¸å] ũҵ»úеѧ±¨Í¶¸åÖÜÆÚ +3 G0DLIN 2026-07-14 7/350 2026-07-15 09:26 by xs74101122
[»ù½ðÉêÇë] ¹ú×ÔÈ»ÃæÉÏD¿ÚÆíµ» +4 monkeynana 2026-07-14 4/200 2026-07-15 09:14 by °×Ë®Öó
[»ù½ðÉêÇë] ûÊÕµ½ÏûÏ¢£¬ÔÙ´ÎÅãÅÜ +3 Ìì¿ÕÐdz½fly 2026-07-14 3/150 2026-07-14 19:14 by 6543yes
[»ù½ðÉêÇë] Ã÷ÌìE¿ÚÃæÉÏ»áÆÀ +8 ²¼²¼ºÍÒ»¶þ 2026-07-12 9/450 2026-07-13 22:59 by QTSorange
ÐÅÏ¢Ìáʾ
ÇëÌî´¦ÀíÒâ¼û