本文整理汇总了Python中htmd.molecule.molecule.Molecule.set方法的典型用法代码示例。如果您正苦于以下问题:Python Molecule.set方法的具体用法?Python Molecule.set怎么用?Python Molecule.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类htmd.molecule.molecule.Molecule
的用法示例。
在下文中一共展示了Molecule.set方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _prep_and_run
# 需要导入模块: from htmd.molecule.molecule import Molecule [as 别名]
# 或者: from htmd.molecule.molecule.Molecule import set [as 别名]
def _prep_and_run(self, mol, rtf, prm, outdir, solvated):
from htmd.builder.solvate import solvate
from htmd.apps.acemdlocal import AcemdLocal
# Do a simple solvation then run for 50ns
ionize = True
mol = Molecule(mol)
mol.center()
mol.set("segid", "L")
d = maxDistance(mol, 'all') + 6
if solvated:
mol = solvate(mol, minmax=[[-d, -d, -d], [d, d, d]])
if not solvated:
ionize = False
build_dir = os.path.join(outdir, "build")
equil_dir = os.path.join(outdir, "equil")
rtfs = ['top/top_water_ions.rtf', rtf]
prms = ['par/par_water_ions.prm', prm]
charmm.build(mol, topo=rtfs, param=prms, outdir=build_dir, ionize=ionize)
md = Equilibration()
md.runtime = 50
md.timeunits = 'ns'
md.temperature = 300
md.write(build_dir, equil_dir)
mdx = AcemdLocal()
mdx.submit(equil_dir)
mdx.wait()
示例2: write
# 需要导入模块: from htmd.molecule.molecule import Molecule [as 别名]
# 或者: from htmd.molecule.molecule.Molecule import set [as 别名]
def write(self, inputdir, outputdir):
""" Write the equilibration protocol
Writes the equilibration protocol and files into a folder for execution
using files inside the inputdir directory
Parameters
----------
inputdir : str
Path to a directory containing the files produced by a build process.
outputdir : str
Directory where to write the equilibration setup files.
Examples
--------
>>> md = Equilibration()
>>> md.write('./build','./equil')
"""
self._findFiles(inputdir)
self._amberFixes()
from htmd.units import convert
numsteps = convert(self.timeunits, 'timesteps', self.runtime, timestep=self.acemd.timestep)
pdbfile = os.path.join(inputdir, self.acemd.coordinates)
inmol = Molecule(pdbfile)
if self.constraintsteps is None:
constrsteps = int(numsteps / 2)
else:
constrsteps = int(self.constraintsteps)
tcl = list(self.acemd.TCL)
tcl[0] = tcl[0].format(NUMSTEPS=numsteps, KCONST=self.fb_k,
REFINDEX=' '.join(map(str, inmol.get('index', self.fb_reference))),
SELINDEX=' '.join(map(str, inmol.get('index', self.fb_selection))),
BOX=' '.join(map(str, self.fb_box)),
NVTSTEPS=self.nvtsteps, CONSTRAINTSTEPS=constrsteps, TEMPERATURE=self.temperature)
self.acemd.TCL = tcl[0] + tcl[1]
if self.acemd.celldimension is None and self.acemd.extendedsystem is None:
coords = inmol.get('coords', sel='water')
if coords.size == 0: # It's a vacuum simulation
coords = inmol.get('coords', sel='all')
dim = np.max(coords, axis=0) - np.min(coords, axis=0)
dim = dim + 12.
else:
dim = np.max(coords, axis=0) - np.min(coords, axis=0)
self.acemd.celldimension = '{} {} {}'.format(dim[0], dim[1], dim[2])
if self.useconstantratio:
self.acemd.useconstantratio = 'on'
self.acemd.setup(inputdir, outputdir, overwrite=True)
# Adding constraints
inmol.set('occupancy', 0)
inmol.set('beta', 0)
for sel in self.constraints:
inmol.set('beta', self.constraints[sel], sel)
outfile = os.path.join(outputdir, self.acemd.coordinates)
inmol.write(outfile)
示例3: write
# 需要导入模块: from htmd.molecule.molecule import Molecule [as 别名]
# 或者: from htmd.molecule.molecule.Molecule import set [as 别名]
def write(self, inputdir, outputdir):
""" Writes the production protocol and files into a folder.
Parameters
----------
inputdir : str
Path to a directory containing the files produced by a equilibration process.
outputdir : str
Directory where to write the production setup files.
"""
self._findFiles(inputdir)
self._amberFixes()
from htmd.units import convert
numsteps = convert(self.timeunits, 'timesteps', self.runtime, timestep=self.acemd.timestep)
self.acemd.temperature = str(self.temperature)
self.acemd.langevintemp = str(self.temperature)
if self.fb_k > 0: #use TCL only for flatbottom
mol = Molecule(os.path.join(inputdir, self.acemd.coordinates))
self.acemd.tclforces = 'on'
tcl = list(self.acemd.TCL)
tcl[0] = tcl[0].format(NUMSTEPS=numsteps, KCONST=self.fb_k,
REFINDEX=' '.join(map(str, mol.get('index', self.fb_reference))),
SELINDEX=' '.join(map(str, mol.get('index', self.fb_selection))),
BOX=' '.join(map(str, self.fb_box)))
self.acemd.TCL = tcl[0] + tcl[1]
else:
self.acemd.TCL = 'set numsteps {}\n'.format(numsteps)
if self.useconstraints:
# Turn on constraints
self.acemd.constraints = 'on'
self.acemd.constraintscaling = '1.0'
else:
if len(self.constraints) != 0:
logger.warning('You have setup constraints to {} but constraints are turned off. '
'If you want to use constraints, define useconstraints=True'.format(self.constraints))
self.acemd.setup(inputdir, outputdir, overwrite=True)
# Adding constraints
if self.useconstraints:
inmol = Molecule(os.path.join(inputdir, self.acemd.coordinates))
inmol.set('occupancy', 0)
inmol.set('beta', 0)
if len(self.constraints) == 0:
raise RuntimeError('You have set the production to use constraints (useconstraints=True), but have not '
'defined any constraints (constraints={}).')
else:
for sel in self.constraints:
inmol.set('beta', self.constraints[sel], sel)
outfile = os.path.join(outputdir, self.acemd.coordinates)
inmol.write(outfile)
self.acemd.consref = self.acemd.coordinates
示例4: write
# 需要导入模块: from htmd.molecule.molecule import Molecule [as 别名]
# 或者: from htmd.molecule.molecule.Molecule import set [as 别名]
def write(self, inputdir, outputdir):
""" Write the equilibration protocol
Writes the equilibration protocol and files into a folder for execution
using files inside the inputdir directory
Parameters
----------
inputdir : str
Path to a directory containing the files produced by a build process.
outputdir : str
Directory where to write the equilibration setup files.
Examples
--------
>>> md = Equilibration()
>>> md.write('./build','./equil')
"""
self._findFiles(inputdir)
self._amberFixes()
pdbfile = os.path.join(inputdir, self.acemd.coordinates)
inmol = Molecule(pdbfile)
self.acemd.TCL = self.acemd.TCL.replace('NUMSTEPS', str(self.numsteps))
self.acemd.TCL = self.acemd.TCL.replace('TEMPERATURE', str(self.temperature))
self.acemd.TCL = self.acemd.TCL.replace('KCONST', str(self.k))
self.acemd.TCL = self.acemd.TCL.replace('REFINDEX', ' '.join(map(str, inmol.get('index', self.reference))))
self.acemd.TCL = self.acemd.TCL.replace('SELINDEX', ' '.join(map(str, inmol.get('index', self.selection))))
self.acemd.TCL = self.acemd.TCL.replace('BOX', ' '.join(map(str, self.box)))
if self.acemd.celldimension is None and self.acemd.extendedsystem is None:
coords = inmol.get('coords', sel='water')
if coords.size == 0: # It's a vacuum simulation
coords = inmol.get('coords', sel='all')
dim = np.max(coords, axis=0) - np.min(coords, axis=0)
dim = dim + 12.
else:
dim = np.max(coords, axis=0) - np.min(coords, axis=0)
self.acemd.celldimension = '{} {} {}'.format(dim[0], dim[1], dim[2])
if self.useconstantratio:
self.acemd.useconstantratio = 'on'
self.acemd.setup(inputdir, outputdir, overwrite=True)
# Adding constraints
inmol.set('occupancy', 0)
inmol.set('beta', 0)
for sel in self.constraints:
inmol.set('beta', self.constraints[sel], sel)
outfile = os.path.join(outputdir, self.acemd.coordinates)
inmol.write(outfile)
示例5: write
# 需要导入模块: from htmd.molecule.molecule import Molecule [as 别名]
# 或者: from htmd.molecule.molecule.Molecule import set [as 别名]
def write(self, inputdir, outputdir):
""" Writes the production protocol and files into a folder.
Parameters
----------
inputdir : str
Path to a directory containing the files produced by a equilibration process.
outputdir : str
Directory where to write the production setup files.
"""
from htmd.molecule.molecule import Molecule
# Do version consistency check
if (self._version == 2 and not isinstance(self.acemd, Acemd2)) and \
(self._version == 3 and not isinstance(self.acemd, Acemd)):
raise RuntimeError('Acemd object version ({}) inconsistent with protocol version at instantiation '
'({})'.format(type(self.acemd), self._version))
self._findFiles(inputdir)
self._amberFixes()
if self._version == 2:
self.acemd.temperature = str(self.temperature)
self.acemd.langevintemp = str(self.temperature)
elif self._version == 3:
self.acemd.temperature = self.temperature
self.acemd.thermostattemp = self.temperature
from htmd.units import convert
numsteps = convert(self.timeunits, 'timesteps', self.runtime, timestep=self.acemd.timestep)
if self._version == 3:
self.acemd.run = str(numsteps)
pdbfile = os.path.join(inputdir, self.acemd.coordinates)
inmol = Molecule(pdbfile)
if np.any(inmol.atomselect('lipids')) and not self.useconstantratio:
logger.warning('Lipids detected in input structure. We highly recommend setting useconstantratio=True '
'for membrane simulations.')
if self._version == 2:
if self.restraints:
raise RuntimeWarning('restraints are only available on {}(_version=3)'.format(self.__class__.__name__))
if self.fb_k > 0: # use TCL only for flatbottom
self.acemd.tclforces = 'on'
if isinstance(self.acemd.TCL, tuple):
tcl = list(self.acemd.TCL)
tcl[0] = tcl[0].format(NUMSTEPS=numsteps, TEMPERATURE=self.temperature, KCONST=self.fb_k,
REFINDEX=' '.join(map(str, inmol.get('index', self.fb_reference))),
SELINDEX=' '.join(map(str, inmol.get('index', self.fb_selection))),
BOX=' '.join(map(str, self.fb_box)))
self.acemd.TCL = tcl[0] + tcl[1]
else:
logger.warning('{} default TCL was already formatted.'.format(self.__class__.__name__))
else:
self.acemd.TCL = 'set numsteps {NUMSTEPS}\n'.format(NUMSTEPS=numsteps)
if self.useconstraints:
# Turn on constraints
self.acemd.constraints = 'on'
self.acemd.constraintscaling = '1.0'
else:
if len(self.constraints) != 0:
logger.warning('You have setup constraints to {} but constraints are turned off. '
'If you want to use constraints, define '
'useconstraints=True'.format(self.constraints))
elif self._version == 3:
if self.restraints is not None:
logger.info('Using user-provided restraints and ignoring constraints and fb_potential')
self.acemd.restraints = self.restraints
else:
restraints = list()
if self.fb_k > 0:
logger.warning('Converting fb_potential to restraints. This is a convenience '
'functional conversion. We recommend start using restraints with '
'{}(_version=3)'.format(self.__class__.__name__))
restraints += self._fb_potential2restraints(inputdir)
if self.useconstraints:
logger.warning('Converting constraints to restraints. This is a convenience '
'functional conversion. We recommend start using restraints with '
'{}(_version=3)'.format(self.__class__.__name__))
restraints += self._constraints2restraints()
else:
if len(self.constraints) != 0:
logger.warning('You have setup constraints to {} but constraints are turned off. '
'If you want to use constraints, define '
'useconstraints=True'.format(self.constraints))
if len(restraints) != 0:
self.acemd.restraints = restraints
if self.useconstantratio:
self.acemd.useconstantratio = 'on'
if self.adaptive:
self.acemd.binvelocities = None
self.acemd.setup(inputdir, outputdir, overwrite=True)
if self._version == 2:
# Adding constraints by writing them to the consref file
if self.useconstraints:
#.........这里部分代码省略.........
示例6: ionizePlace
# 需要导入模块: from htmd.molecule.molecule import Molecule [as 别名]
# 或者: from htmd.molecule.molecule.Molecule import set [as 别名]
def ionizePlace(mol, anion_resname, cation_resname, anion_name, cation_name, nanion, ncation, dfrom=5, dbetween=5, segname=None):
"""Place a given number of negative and positive ions in the solvent.
Replaces water molecules al long as they respect the given distance criteria.
Parameters
----------
mol : :class:`Molecule <htmd.molecule.molecule.Molecule>` object
The Molecule object
anion_resname : str
Resname of the added anions
cation_resname : str
Resname of the added cations
anion_name : str
Name of the added anions
cation_name : str
Name of the added cations
nanion : int
Number of anions to add
ncation : int
Number of cations to add
dfrom : float
Min distance of ions from molecule
dbetween : float
Min distance between ions
segname : str
Segment name to add
Returns
-------
mol : :class:`Molecule <htmd.molecule.molecule.Molecule>` object
The molecule with the ions added
"""
newmol = mol.copy()
logger.debug('Min distance of ions from molecule: ' + str(dfrom) + 'A')
logger.debug('Min distance between ions: ' + str(dbetween) + 'A')
logger.debug('Placing {:d} anions and {:d} cations.'.format(nanion,ncation))
if (nanion + ncation) == 0:
return newmol
nions = nanion + ncation
betabackup = newmol.beta.copy()
newmol.set('beta', sequenceID((newmol.resid, newmol.insertion, newmol.segid)))
# Find water oxygens to replace with ions
ntries = 0
maxtries = 10
while True:
ionlist = []
watindex = newmol.atomselect('noh and water and not (within ' + str(dfrom) + ' of not water)', indexes=True)
watsize = len(watindex)
if watsize == 0:
raise NameError('No waters could be found further than ' + str(dfrom) + ' from other molecules to be replaced by ions. You might need to solvate with a bigger box or disable the ionize property when building.')
while len(ionlist) < nions:
if len(watindex) == 0:
break
randwat = np.random.randint(len(watindex))
thision = watindex[randwat]
addit = True
if len(ionlist) != 0: # Check for distance from precious ions
ionspos = newmol.get('coords', sel=ionlist)
thispos = newmol.get('coords', sel=thision)
dists = distance.cdist(np.atleast_2d(ionspos), np.atleast_2d(thispos), metric='euclidean')
if np.any(dists < dbetween):
addit = False
if addit:
ionlist.append(thision)
watindex = np.delete(watindex, randwat)
if len(ionlist) == nions:
break
ntries += 1
if ntries == maxtries:
raise NameError('Failed to add ions after ' + str(maxtries) + ' attempts. Try decreasing the ''from'' and ''between'' parameters, decreasing ion concentration or making a larger water box.')
# Delete waters but keep their coordinates
waterpos = np.atleast_2d(newmol.get('coords', ionlist))
betasel = np.zeros(newmol.numAtoms, dtype=bool)
for b in newmol.beta[ionlist]:
betasel |= newmol.beta == b
atmrem = np.sum(betasel)
atmput = 3 * len(ionlist)
# assert atmrem == atmput, 'Removing {} atoms instead of {}. Report this bug.'.format(atmrem, atmput)
sel = np.where(betasel)[0]
newmol.remove(sel, _logger=False)
# assert np.size(sel) == atmput, 'Removed {} atoms instead of {}. Report this bug.'.format(np.size(sel), atmput)
betabackup = np.delete(betabackup, sel)
# Add the ions
randidx = np.random.permutation(np.size(waterpos, 0))
atom = Molecule()
atom.empty(1)
atom.set('chain', 'I')
#.........这里部分代码省略.........
示例7: write
# 需要导入模块: from htmd.molecule.molecule import Molecule [as 别名]
# 或者: from htmd.molecule.molecule.Molecule import set [as 别名]
def write(self, inputdir, outputdir):
""" Write the equilibration protocol
Writes the equilibration protocol and files into a folder for execution
using files inside the inputdir directory
Parameters
----------
inputdir : str
Path to a directory containing the files produced by a build process.
outputdir : str
Directory where to write the equilibration setup files.
Examples
--------
>>> md = Equilibration()
>>> md.write('./build','./equil')
"""
self._findFiles(inputdir)
self._amberFixes()
from htmd.units import convert
numsteps = convert(self.timeunits, 'timesteps', self.runtime, timestep=self.acemd.timestep)
pdbfile = os.path.join(inputdir, self.acemd.coordinates)
inmol = Molecule(pdbfile)
if np.any(inmol.atomselect('lipids')) and not self.useconstantratio:
logger.warning('Lipids detected in input structure. We highly recommend setting useconstantratio=True '
'for membrane simulations.')
if self.constraintsteps is None:
constrsteps = int(numsteps / 2)
else:
constrsteps = int(self.constraintsteps)
if isinstance(self.acemd.TCL, tuple):
tcl = list(self.acemd.TCL)
tcl[0] = tcl[0].format(NUMSTEPS=numsteps, KCONST=self.fb_k,
REFINDEX=' '.join(map(str, inmol.get('index', self.fb_reference))),
SELINDEX=' '.join(map(str, inmol.get('index', self.fb_selection))),
BOX=' '.join(map(str, self.fb_box)),
NVTSTEPS=self.nvtsteps, CONSTRAINTSTEPS=constrsteps, TEMPERATURE=self.temperature)
self.acemd.TCL = tcl[0] + tcl[1]
else:
logger.warning('{} default TCL was already formatted.'.format(self.__class__.__name__))
if self.acemd.celldimension is None and self.acemd.extendedsystem is None:
coords = inmol.get('coords', sel='water')
if coords.size == 0: # It's a vacuum simulation
coords = inmol.get('coords', sel='all')
dim = np.max(coords, axis=0) - np.min(coords, axis=0)
dim = dim + 12.
else:
dim = np.max(coords, axis=0) - np.min(coords, axis=0)
self.acemd.celldimension = '{} {} {}'.format(dim[0], dim[1], dim[2])
if self.useconstantratio:
self.acemd.useconstantratio = 'on'
self.acemd.setup(inputdir, outputdir, overwrite=True)
# Adding constraints by writing them to the consref file
inconsreffile = os.path.join(inputdir, self.acemd.consref)
consrefmol = Molecule(inconsreffile)
consrefmol.set('occupancy', 0)
consrefmol.set('beta', 0)
if len(self.constraints) == 0:
raise RuntimeError('You have not defined any constraints for the Equilibration (constraints={}).')
else:
for sel in self.constraints:
consrefmol.set('beta', self.constraints[sel], sel)
outconsreffile = os.path.join(outputdir, self.acemd.consref)
consrefmol.write(outconsreffile)
示例8: ionizePlace
# 需要导入模块: from htmd.molecule.molecule import Molecule [as 别名]
# 或者: from htmd.molecule.molecule.Molecule import set [as 别名]
def ionizePlace(mol, anion, cation, anionatom, cationatom, nanion, ncation, dfrom=5, dbetween=5, segname=None):
newmol = mol.copy()
logger.info('Min distance of ions from molecule: ' + str(dfrom) + 'A')
logger.info('Min distance between ions: ' + str(dbetween) + 'A')
logger.info('Placing ' + str(nanion+ncation) + ' ions.')
if (nanion + ncation) == 0:
return newmol
segname = _getSegname(newmol, segname)
nions = nanion + ncation
betabackup = newmol.beta
newmol.set('beta', sequenceID((newmol.resid, newmol.segid)))
# Find water oxygens to replace with ions
ntries = 0
maxtries = 10
while True:
ionlist = np.empty(0, dtype=int)
watindex = newmol.atomselect('noh and water and not (within ' + str(dfrom) + ' of not water)', indexes=True)
watsize = len(watindex)
if watsize == 0:
raise NameError('No waters could be found further than ' + str(dfrom) + ' from other molecules to be replaced by ions. You might need to solvate with a bigger box or disable the ionize property when building.')
while len(ionlist) < nions:
if len(watindex) == 0:
break
randwat = np.random.randint(len(watindex))
thision = watindex[randwat]
addit = True
if len(ionlist) != 0: # Check for distance from precious ions
ionspos = newmol.get('coords', sel=ionlist)
thispos = newmol.get('coords', sel=thision)
dists = distance.cdist(np.atleast_2d(ionspos), np.atleast_2d(thispos), metric='euclidean')
if np.any(dists < dbetween):
addit = False
if addit:
ionlist = np.append(ionlist, thision)
watindex = np.delete(watindex, randwat)
if len(ionlist) == nions:
break
ntries += 1
if ntries == maxtries:
raise NameError('Failed to add ions after ' + str(maxtries) + ' attempts. Try decreasing the ''from'' and ''between'' parameters, decreasing ion concentration or making a larger water box.')
# Delete waters but keep their coordinates
waterpos = np.atleast_2d(newmol.get('coords', ionlist))
stringsel = 'beta'
for x in newmol.beta[ionlist]:
stringsel += ' ' + str(int(x))
atmrem = np.sum(newmol.atomselect(stringsel))
atmput = 3 * len(ionlist)
# assert atmrem == atmput, 'Removing {} atoms instead of {}. Report this bug.'.format(atmrem, atmput)
sel = newmol.atomselect(stringsel, indexes=True)
newmol.remove(sel, _logger=False)
# assert np.size(sel) == atmput, 'Removed {} atoms instead of {}. Report this bug.'.format(np.size(sel), atmput)
betabackup = np.delete(betabackup, sel)
# Add the ions
randidx = np.random.permutation(np.size(waterpos, 0))
atom = Molecule()
atom.empty(1)
atom.set('chain', 'I')
atom.set('segid', 'I')
for i in range(nanion):
atom.set('name', anionatom)
atom.set('resname', anion)
atom.set('resid', newmol.resid[-1] + 1)
atom.coords = waterpos[randidx[i], :]
newmol.insert(atom, len(newmol.name))
for i in range(ncation):
atom.set('name', cationatom)
atom.set('resname', cation)
atom.set('resid', newmol.resid[-1] + 1)
atom.coords = waterpos[randidx[i+nanion], :]
newmol.insert(atom, len(newmol.name))
# Restoring the original betas
sel = np.ones(len(betabackup) + nions, dtype=bool)
sel[len(betabackup)::] = False
newmol.set('beta', betabackup, sel=sel)
return newmol
示例9: write
# 需要导入模块: from htmd.molecule.molecule import Molecule [as 别名]
# 或者: from htmd.molecule.molecule.Molecule import set [as 别名]
def write(self, inputdir, outputdir):
""" Writes the production protocol and files into a folder.
Parameters
----------
inputdir : str
Path to a directory containing the files produced by a equilibration process.
outputdir : str
Directory where to write the production setup files.
"""
self._findFiles(inputdir)
self._amberFixes()
self.acemd.temperature = self.temperature
self.acemd.langevintemp = self.temperature
from htmd.units import convert
numsteps = convert(self.timeunits, 'timesteps', self.runtime, timestep=self.acemd.timestep)
pdbfile = os.path.join(inputdir, self.acemd.coordinates)
inmol = Molecule(pdbfile)
if np.any(inmol.atomselect('lipids')) and not self.useconstantratio:
logger.warning('Lipids detected in input structure. We highly recommend setting useconstantratio=True '
'for membrane simulations.')
if self.fb_k > 0: # use TCL only for flatbottom
self.acemd.tclforces = 'on'
tcl = list(self.acemd.TCL)
tcl[0] = tcl[0].format(NUMSTEPS=numsteps, TEMPERATURE=self.temperature, KCONST=self.fb_k,
REFINDEX=' '.join(map(str, inmol.get('index', self.fb_reference))),
SELINDEX=' '.join(map(str, inmol.get('index', self.fb_selection))),
BOX=' '.join(map(str, self.fb_box)))
self.acemd.TCL = tcl[0] + tcl[1]
else:
self.acemd.TCL = 'set numsteps {NUMSTEPS}\n' \
'set temperature {TEMPERATURE}\n'.format(NUMSTEPS=numsteps, TEMPERATURE=self.temperature)
if self.useconstraints:
# Turn on constraints
self.acemd.constraints = 'on'
self.acemd.constraintscaling = 1.0
else:
if len(self.constraints) != 0:
logger.warning('You have setup constraints to {} but constraints are turned off. '
'If you want to use constraints, define useconstraints=True'.format(self.constraints))
if self.useconstantratio:
self.acemd.useconstantratio = 'on'
if self.adaptive:
self.acemd.binvelocities = None
self.acemd.setup(inputdir, outputdir, overwrite=True)
# Adding constraints by writing them to the consref file
if self.useconstraints:
inconsreffile = os.path.join(inputdir, self.acemd.consref)
consrefmol = Molecule(inconsreffile)
consrefmol.set('occupancy', 0)
consrefmol.set('beta', 0)
if len(self.constraints) == 0:
raise RuntimeError('You have set the production to use constraints (useconstraints=True), but have not '
'defined any constraints (constraints={}).')
else:
for sel in self.constraints:
consrefmol.set('beta', self.constraints[sel], sel)
outconsreffile = os.path.join(outputdir, self.acemd.consref)
consrefmol.write(outconsreffile)
示例10: write
# 需要导入模块: from htmd.molecule.molecule import Molecule [as 别名]
# 或者: from htmd.molecule.molecule.Molecule import set [as 别名]
def write(self, inputdir, outputdir):
""" Write the equilibration protocol
Writes the equilibration protocol and files into a folder for execution
using files inside the inputdir directory
Parameters
----------
inputdir : str
Path to a directory containing the files produced by a build process.
outputdir : str
Directory where to write the equilibration setup files.
Examples
--------
>>> md = Equilibration()
>>> md.write('./build','./equil')
"""
from htmd.molecule.molecule import Molecule
# Do version consistency check
if (self._version == 2 and not isinstance(self.acemd, Acemd2)) and \
(self._version == 3 and not isinstance(self.acemd, Acemd)):
raise RuntimeError('Acemd object version ({}) inconsistent with protocol version at instantiation '
'({})'.format(type(self.acemd), self._version))
self._findFiles(inputdir)
self._amberFixes()
from htmd.units import convert
numsteps = convert(self.timeunits, 'timesteps', self.runtime, timestep=self.acemd.timestep)
if self._version == 3:
self.acemd.temperature = self.temperature
self.acemd.thermostattemp = self.temperature
self.acemd.run = str(numsteps)
pdbfile = os.path.join(inputdir, self.acemd.coordinates)
inmol = Molecule(pdbfile)
if np.any(inmol.atomselect('lipids')) and not self.useconstantratio:
logger.warning('Lipids detected in input structure. We highly recommend setting useconstantratio=True '
'for membrane simulations.')
if self.constraintsteps is None:
constrsteps = int(numsteps / 2)
else:
constrsteps = int(self.constraintsteps)
if self._version == 2:
if self.restraints:
raise RuntimeWarning('restraints are only available on {}(_version=3)'.format(self.__class__.__name__))
if isinstance(self.acemd.TCL, tuple):
tcl = list(self.acemd.TCL)
tcl[0] = tcl[0].format(NUMSTEPS=numsteps, KCONST=self.fb_k,
REFINDEX=' '.join(map(str, inmol.get('index', self.fb_reference))),
SELINDEX=' '.join(map(str, inmol.get('index', self.fb_selection))),
BOX=' '.join(map(str, self.fb_box)),
NVTSTEPS=self.nvtsteps, CONSTRAINTSTEPS=constrsteps, TEMPERATURE=self.temperature)
self.acemd.TCL = tcl[0] + tcl[1]
else:
logger.warning('{} default TCL was already formatted.'.format(self.__class__.__name__))
elif self._version == 3:
if self.restraints is not None:
logger.info('Using user-provided restraints and ignoring constraints and fb_potential')
self.acemd.restraints = self.restraints
else:
logger.warning('Converting constraints and fb_potential to restraints. This is a convenience '
'functional conversion. We recommend start using restraints with '
'{}(_version=3)'.format(self.__class__.__name__))
restraints = list()
# convert constraints to restraints and add them
if self.constraints is not None:
restraints += self._constraints2restraints(constrsteps)
# convert fb_potential to restraints and add them
if self.fb_k > 0:
restraints += self._fb_potential2restraints(inputdir)
self.acemd.restraints = restraints
if self.acemd.celldimension is None and self.acemd.extendedsystem is None:
coords = inmol.get('coords', sel='water')
if coords.size == 0: # It's a vacuum simulation
coords = inmol.get('coords', sel='all')
dim = np.max(coords, axis=0) - np.min(coords, axis=0)
dim += 12.
else:
dim = np.max(coords, axis=0) - np.min(coords, axis=0)
self.acemd.celldimension = '{} {} {}'.format(dim[0], dim[1], dim[2])
if self.useconstantratio:
self.acemd.useconstantratio = 'on'
self.acemd.setup(inputdir, outputdir, overwrite=True)
if self._version == 2:
# Adding constraints by writing them to the consref file
inconsreffile = os.path.join(inputdir, self.acemd.consref)
consrefmol = Molecule(inconsreffile)
consrefmol.set('occupancy', 0)
consrefmol.set('beta', 0)
#.........这里部分代码省略.........