±±¾©Ê¯ÓÍ»¯¹¤Ñ§Ôº2026ÄêÑо¿ÉúÕÐÉú½ÓÊÕµ÷¼Á¹«¸æ
²é¿´: 1096  |  »Ø¸´: 3

zyj8119

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

[½»Á÷] ¡¾Ô­´´¡¿MAPSÖй¹ÖþlammpsµÄÎÞ¶¨ÐνṹµÄpython³ÌÐò ÒÑÓÐ3È˲ÎÓë

CODE:
#!/usr/bin/python
###########################################################################
#                        amorphousLAMMPS.py  -  description
#                        ----------------------------------
#   begin                : Tue Oct  7 18:23:23 EEST 2008
#   copyright            : (C) 2008 by Scienomics
#   email                : loukas.peristeras@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) 2008 Scienomics S. A.                                   #
#                                                                         #
###########################################################################
#
#   $Id: amorphousLAMMPS.py,v 1.4 2010/01/30 08:32:20 lperi Exp $
#   $Log: amorphousLAMMPS.py,v $
#   Revision 1.4  2010/01/30 08:32:20  lperi
#   Fix version handling.
#
#   Revision 1.3  2010/01/26 22:12:53  lperi
#   Fix bug 3182.
#
#   Revision 1.2  2010/01/04 19:29:03  lperi
#   Update with recoil growth.
#
#   Revision 1.1  2008/10/27 08:37:28  jrh
#   Created
#
#   $Revision: 1.4 $
#   $Release$

# Script to demonstrate the Amorphous Builder functionality in
# combination with LAMMPS optimizer.
# - builds a 100mer chain (Ethylene monomer is used with Dreiding force
#   field assigned)
# - builds a amorphous system (2 chains, 0.79 g/cm3) is build
# - perform LAMMPS optimization on the resulting system

import os
import time
import Maps
import MapsChemistryDataModel
import MapsViewer
import MapsLAMMPS
import MapsAmorphousBuilder
from PyQt4 import *

class AmorphousBuilderProtocol():
  """ The protocol used to prepare an amorphous cell of a given
      set of molecules.
  """
  plugin=MapsAmorphousBuilder.AmorphousBuilderPlugin.get()
  builder=None

  def create(self, molecule, nchain, density, temperature):
    self.builder=MapsAmorphousBuilder.AmorphousBuilder(app)
    self.builder.setFlexible(True)
    self.builder.setSimultaneously(True)
    self.builder.setNewProject(False)
    self.builder.setTemperature(temperature)
    self.builder.setDensity(density)
    self.builder.setInsertLateral(False)
    self.builder.setNumberOfInsertionTrials(50)
    self.builder.setNumberOfBuildTrials(5)
    self.builder.setNumberOfMoleculeBuildTrials(5)
    self.builder.setNumberOfBackSteps(5)
    self.builder.setNumberOfTrials(12)
    self.builder.setRecoiGrowth(True)
    self.builder.setScaleGroup(1.0)
    self.builder.setScaleLateralBonds(1.0)
    self.builder.setScaleBonds(1.0)
    self.builder.useNonBondedInteractions(True)
    self.builder.initializeRandomNumber(1234);

    molecules = [molecule]
    nmolecules = [nchain]
    self.builder.setMolecules(molecules,nmolecules)

    self.plugin.setBuilder(self.builder)
    self.builder.runningInThread=False

    app.statusBar().showMessage("Building amorphous system...")
    QtGui.qApp.processEvents()
    self.builder.startBuilder(False)
    QtGui.qApp.processEvents()
    app.statusBar().showMessage("Ready")
    QtGui.qApp.processEvents()
    if ( self.builder.getMolecule() ):
      self.builder.getMolecule().setName("amorphous")
      return(1)
    else:
      return(0)

  def getMolecule(self):
    if self.builder:
      return(self.builder.getMolecule())
    else:
      return(None)

class OptimizationProtocol:
  """ The protocol used to optimize the system.
  """
  plugin=MapsLAMMPS.LAMMPSPlugin.get()
  results=None
  molecule=None
  jobName=""
  projectName=""

  def setup(self):
    writer=MapsLAMMPS.LAMMPSWriter(app, self.plugin)
    writer.setOption("coordinateFile", self.jobName + ".data")
    writer.setOption("cutoff", "11.0")
    writer.setOption("dielectric", "1.0")
    writer.setOption("energyConvergence", "0.0001")
    writer.setOption("ensemble", "NVE")
    writer.setOption("forceCalculations", "5000")
    writer.setOption("forceConvergence", "0.000001")
    writer.setOption("forceFile", self.jobName + ".frcdump")
    writer.setOption("initialTemperature", "298.15")
    writer.setOption("method", "conjugatedGradient")
    writer.setOption("restartAtEnd", self.jobName)
    writer.setOption("scale12", "0.0")
    writer.setOption("scale12Coulomb", "0.0")
    writer.setOption("scale13", "0.0")
    writer.setOption("scale13Coulomb", "0.0")
    writer.setOption("scale14", "1.0")
    writer.setOption("scale14Coulomb", "1.0")
    writer.setOption("seed", str(int(time.time())))
    writer.setOption("steps", "500")
    writer.setOption("switchDistance", "8.0")
    writer.setOption("switching", "on")
    writer.setOption("timestep", "1")
    writer.setOption("title", self.jobName)
    writer.setOption("trajectoryFile", self.jobName + ".dump")
    writer.setOption("trajectoryFrequency", "100")
    writer.setOption("type", "forcefield")
    writer.setOption("typeOfCalculation", "optimization")
    writer.setOption("velocityFile", self.jobName + ".veldump")
    success=writer.createInput(self.results,self.molecule, self.jobName)
    if not success:
      QMessageBox.critical(app, "Note",  writer.getErrorDescription())
    return(success)

  def checkStatus(self):
    file=open("status", "r")
    line=file.readline()
    file.close()
    if line == "Completed":
      return(1)
    else:
      return(0)

  def optimize(self,molecule):
    self.molecule=molecule
    self.jobName=molecule.getName()+"_opt"
    self.projectName=cdm.findProjectNameForMolecule(self.molecule)
    # Add an experiment
    project=cdm.findProjectByName(self.projectName)
    experiment=Maps.Experiment(cdm,None,project,DataObject.END_TYPE)
    experiment.setName("LAMMPS " + str(self.molecule.getName()) + " optimization")
    project.addExperiment(experiment)
    self.results=Maps.ExperimentalResult(cdm,experiment)
    self.results.setName("LAMMPS results for " + str(self.molecule.getName()))
    experiment.addExperimentalResult(self.results)
    app.statusBar().showMessage("Optimizing structure using LAMMPS ...")
    # Setup LAMMPS optimization
    dirName=str(workingDirectory + "/" + self.jobName)
    if not os.path.exists(dirName):
      os.mkdir(dirName)
    os.chdir(dirName)
    success=0
    if self.setup():
      if os.name == "posix":
        prefix="./"
      else:
        prefix=""
      os.system(prefix + "run.py")
      if self.checkStatus():
        m=self.plugin.loadFile(self.results, \
                             self.jobName.toLatin1() + ".log")
        success=1
      else:
        QtGui.QMessageBox.critical(app, "Note", "The optimization using LAMMPS failed.")
    os.chdir("..")
    app.statusBar().showMessage("Ready")
    QtGui.qApp.processEvents()
    return(success)

def main():
  # Create output project
  project=MapsChemistryDataModel.Project(cdm)
  project.setName("Python polymer builder")
  cdm.addProject(project)

  # Find path to MAPS installation
  for d in app.getInstallPath():
    dir=d.toLatin1()
    if os.path.exists(dir): break
  file = "Ethylene.cml"
  fileName=dir + "/groups/Monomers/" + file

  # Build 100 mer chain
  print "Building polymer ..."
  molecule=MapsChemistryDataModel.Molecule(cdm)
  project.addMolecule(molecule)
  viewerPlugin.start(molecule)
  viewer=viewerPlugin.getActiveViewer()
  QtGui.qApp.processEvents()
  chainLength=100
  molecule.setName(str(chainLength) + "mer of " + file[0:len(file)-4])
  monomer=MapsViewer.Monomer(fileName, "Monomer", chainLength)
  monomers=[]
  monomers.append(monomer)
  viewer.buildPolymer(monomers, 1, 1, 0, MapsViewer.Viewer.ISOTACTIC)
  del monomers
  QtGui.qApp.processEvents()

  # Assign Dreiding force field
  print "Assigning force field ..."
  ff=MapsChemistryDataModel.ForceField(cdm, dir + "/forcefields/Dreiding.params")
  handler=MapsChemistryDataModel.ForceFieldHandler(app,ff.getForceFieldPath(),"")
  nullarg=None
  handler.setMolecule(molecule,nullarg)
  atomType=True
  atomCharge=True
  if handler.assignForceField(atomType,atomCharge):
    QtGui.QMessageBox.information(app, "Note", "The Dreiding force field was assigned.")
  else:
    QtGui.QMessageBox.warning(app, "Note", "There was a problem with the assignment\nof the force field.")
  QtGui.qApp.processEvents()

  # Create a amorphous system of 5 chains (0.79 g/cm3)
  nchain=2
  density=0.79
  temperature=450.0

  builder=AmorphousBuilderProtocol()
  print "Building amorphous system ..."
  if not builder.create(molecule,nchain,density,temperature):
    QtGui.QMessageBox.information(app, "Note", "Amorphous builder failed.")
  else:
    print "Optimizing amorphous system ..."
    optimizer=OptimizationProtocol()
    if not optimizer.optimize(builder.getMolecule()):
      QtGui.QMessageBox.information(app, "Note", "Optimization failed.")
  QtGui.qApp.processEvents()

#-------------------------
if __name__ == '__main__':
  # Check if MAPS is at least at version 3.2
  try:
    version=Maps.MapsApp.getVersion()
  except (TypeError, AttributeError):
    version=0
  if version < 302:
    QtGui.QMessageBox.information(None, "Note", "This script requires at least MAPS version 3.2.")
  else:
    # Get plugins needed
    app=Maps.MapsApp.getContainer()
    cdm=MapsChemistryDataModel.ChemistryDataModel.get()
    viewerPlugin=MapsViewer.ViewerPlugin.get()
    workingDirectory=app.getPreference("Working directory")
    main()

»Ø¸´´ËÂ¥

» ²ÂÄãϲ»¶

» ±¾Ö÷ÌâÏà¹Ø¼ÛÖµÌùÍÆ¼ö£¬¶ÔÄúͬÑùÓаïÖú:

ºÃºÃѧϰ£¬ÌìÌìÏòÉÏ¡£
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

amynihao

½ð³æ (ÕýʽдÊÖ)

¼Åį´ó³æ

¡ï
Сľ³æ(½ð±Ò+0.5):¸ø¸öºì°ü£¬Ð»Ð»»ØÌû½»Á÷
ÒýÓûØÌû:
Originally posted by zyj8119 at 2010-12-26 17:41:04:
[code]#!/usr/bin/python
###########################################################################
#                        amorphousLAMMPS.py  -  description
#                        --------- ...

ר¼ÒÄúºÃ£¬Õâ¸ö³ÌÐòÊÇÓÃÀ´²úÉúÎÞ¶¨ÐνṹµÄÂð£¿ÄǹèËáÑεIJ£Á§Ì¬µÄ½á¹¹¿ÉÒÔÓÃÕâ¸ö³ÌÐòÂð£¿Õâ¸ö³ÌÐòÊÇlammpsÀïµÄ£¬¿ÉÒÔÄâºÏµ½MSÀïÂð£¿
²»ÊÇÒª×öÒ»¸öµ¥´¿ÓÅÐãµÄÈË£¬¶øÊÇÒª×öÒ»¸ö²»¿ÉÌæ´úµÄÈË¡£
2Â¥2010-12-28 09:11:21
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

zyj8119

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

¡ï ¡ï
zh1987hs(½ð±Ò+2):лл 2011-01-14 14:46:30
ÒýÓûØÌû:
Originally posted by amynihao at 2010-12-28 09:11:21:

ר¼ÒÄúºÃ£¬Õâ¸ö³ÌÐòÊÇÓÃÀ´²úÉúÎÞ¶¨ÐνṹµÄÂð£¿ÄǹèËáÑεIJ£Á§Ì¬µÄ½á¹¹¿ÉÒÔÓÃÕâ¸ö³ÌÐòÂð£¿Õâ¸ö³ÌÐòÊÇlammpsÀïµÄ£¬¿ÉÒÔÄâºÏµ½MSÀïÂð£¿

ÎÞ¶¨ÐεĽṹ£¬Ö»ÄÜ×Ô¼º±à³Ì£¬ÓÃËæ»úÊý²úÉú³ÌÐò¡£
ºÃºÃѧϰ£¬ÌìÌìÏòÉÏ¡£
3Â¥2011-01-13 15:49:40
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

hbcsucy

ľ³æ (СÓÐÃûÆø)

AAA

¡ï
Сľ³æ(½ð±Ò+0.5):¸ø¸öºì°ü£¬Ð»Ð»»ØÌû½»Á÷
mapsÈí¼þÄÇÀïÓа¡£¿Òª¶àÉÙÇ®°¡£¿¡£¡£¡£¡£
day day
4Â¥2011-01-15 21:30:48
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû
Ïà¹Ø°æ¿éÌø×ª ÎÒÒª¶©ÔÄÂ¥Ö÷ zyj8119 µÄÖ÷Ìâ¸üÐÂ
×î¾ßÈËÆøÈÈÌûÍÆ¼ö [²é¿´È«²¿] ×÷Õß »Ø/¿´ ×îºó·¢±í
[¿¼ÑÐ] »·¾³×¨Ë¶µ÷¼Á +4 »á˵»°µÄÖâ×Ó 2026-04-06 4/200 2026-04-06 17:28 by dongzh2009
[¿¼ÑÐ] ÉúÎïѧѧ˶Çóµ÷¼Á£º351·ÖÒ»Ö¾Ô¸ÄϾ©Ê¦·¶´óѧÉúÎïѧרҵ +5 ¡­¡«¡¢Íõ¡­¡« 2026-04-06 6/300 2026-04-06 16:12 by dooble
[¿¼ÑÐ] 336²ÄÁÏÓ뻯¹¤085600Çóµ÷¼Á +9 Ë®ÐǼÇinfp 2026-04-05 12/600 2026-04-06 11:46 by Ë®ÐǼÇinfp
[¿¼ÑÐ] ר˶0854³õÊÔ¿¼²Ä¿Æ»ù£¬Çóµ÷¼Á +6 3220548044 2026-04-06 9/450 2026-04-06 10:26 by barlinike
[¿¼ÑÐ] Ò»Ö¾Ô¸±±¾©»¯¹¤085600 310·ÖÇóµ÷¼Á +16 0856²ÄÁÏÓ뻯¹¤3 2026-04-04 18/900 2026-04-06 01:54 by BruceLiu320
[¿¼ÑÐ] 266·Ö£¬Ò»Ö¾Ô¸µçÆø¹¤³Ì£¬±¾¿Æ²ÄÁÏ£¬Çó²ÄÁÏרҵµ÷¼Á +8 ÍÛºôºßºôºß 2026-04-02 9/450 2026-04-05 17:14 by lbsjt
[¿¼ÑÐ] Çó +5 »¯¹¤×¨Ë¶323·Ö 2026-04-04 5/250 2026-04-05 08:02 by 544594351
[¿¼ÑÐ] ²ÄÁϹ¤³Ì085601Êý¶þÓ¢Ò»335Çóµ÷¼Á +6 Ë«ÂíβƦÀϰå2 2026-03-31 6/300 2026-04-04 22:29 by hemengdong
[¿¼ÑÐ] 319Çóµ÷¼Á +4 ÐÇÐDz»Õ£ÑÛà¶ 2026-04-03 4/200 2026-04-04 16:25 by ÖзÉÔº¿Õ¹ÜѧԺÑ
[¿¼ÑÐ] 311Çóµ÷¼Á +20 zchqwer 2026-04-01 22/1100 2026-04-03 22:09 by lglzsd
[¿¼ÑÐ] Çóµ÷¼Á²»Ìôרҵ +3 xrh030412 2026-04-01 3/150 2026-04-03 14:40 by µªÆøÆøÆø
[¿¼ÑÐ] 273Çóµ÷¼Á +20 ÀîÜÆÐÂ1 2026-03-31 20/1000 2026-04-03 09:58 by linyelide
[¿¼ÑÐ] Ò»Ö¾Ô¸°²»Õ´óѧ0817»¯Ñ§¹¤³ÌÓë¼¼Êõ£¬Çóµ÷¼Á +14 ÎÒ²»ÊÇÖ»Òò 2026-04-02 15/750 2026-04-03 09:49 by À¶ÔÆË¼Óê
[¿¼ÑÐ] 312 »¯¹¤»òÖÆÒ©µ÷¼Á +8 ССī123 2026-04-02 9/450 2026-04-03 09:12 by zhouxiaoyu
[¿¼ÑÐ] 282Çóµ÷¼Á +13 ºôÎü¶¼ÊǼõ·Ê 2026-04-01 13/650 2026-04-02 14:10 by baoball
[¿¼ÑÐ] 0856³õÊÔ324·ÖÇóµ÷¼Á +6 ÏëÉÏѧÇóµ÷ 2026-04-01 6/300 2026-04-02 11:42 by ÐÇ¿ÕÐÇÔÂ
[¿¼ÑÐ] 261ÇóBÇøµ÷¼Á +5 Ã÷×С¤ 2026-04-01 7/350 2026-04-02 11:17 by ×Þξξ
[¿¼ÑÐ] 302Çóµ÷¼ÁÒ»Ö¾Ô¸±±º½070300£¬±¾¿ÆÖ£´ó»¯Ñ§ +8 Ê¥ÈÕ¶úÂüÌõ 2026-04-01 11/550 2026-04-02 07:40 by chemdavid
[¿¼ÑÐ] 085602»¯Ñ§¹¤³Ì268·Ö¶×µ÷¼Á +8 ÔÂÕÕ»¨ÁÖ¡£ 2026-04-01 8/400 2026-04-01 22:08 by Î޼ʵIJÝÔ­
[¿¼ÑÐ] Çóµ÷¼Á£ºÒ»Ö¾Ô¸£ºÄϾ©´óѧ רҵ£º0705 ×Ü·Ö320 £¬±¾¿Æ985£¬ËÄÁù¼¶Òѹý +3 lfy760306 2026-03-31 3/150 2026-04-01 01:57 by Creta
ÐÅÏ¢Ìáʾ
ÇëÌî´¦ÀíÒâ¼û