本文整理汇总了Python中htmd.molecule.molecule.Molecule.resid方法的典型用法代码示例。如果您正苦于以下问题:Python Molecule.resid方法的具体用法?Python Molecule.resid怎么用?Python Molecule.resid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类htmd.molecule.molecule.Molecule
的用法示例。
在下文中一共展示了Molecule.resid方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _fillMolecule
# 需要导入模块: from htmd.molecule.molecule import Molecule [as 别名]
# 或者: from htmd.molecule.molecule.Molecule import resid [as 别名]
def _fillMolecule(name, resname, chain, resid, insertion, coords, segid, elements):
numAtoms = len(name)
mol = Molecule()
mol.empty(numAtoms)
mol.name = np.array(name, dtype=mol._pdb_fields['name'])
mol.resname = np.array(resname, dtype=mol._pdb_fields['resname'])
mol.chain = np.array(chain, dtype=mol._pdb_fields['chain'])
mol.resid = np.array(resid, dtype=mol._pdb_fields['resid'])
mol.insertion = np.array(insertion, dtype=mol._pdb_fields['insertion'])
mol.coords = np.array(np.atleast_3d(np.vstack(coords)), dtype=mol._pdb_fields['coords'])
mol.segid = np.array(segid, dtype=mol._pdb_fields['segid'])
mol.element = np.array(elements, dtype=mol._pdb_fields['element'])
return mol
示例2: _fillMolecule
# 需要导入模块: from htmd.molecule.molecule import Molecule [as 别名]
# 或者: from htmd.molecule.molecule.Molecule import resid [as 别名]
def _fillMolecule(name, resname, chain, resid, insertion, coords, segid, element,
occupancy, beta, charge, record):
numAtoms = len(name)
mol = Molecule()
mol.empty(numAtoms)
mol.name = np.array(name, dtype=mol._dtypes['name'])
mol.resname = np.array(resname, dtype=mol._dtypes['resname'])
mol.chain = np.array(chain, dtype=mol._dtypes['chain'])
mol.resid = np.array(resid, dtype=mol._dtypes['resid'])
mol.insertion = np.array(insertion, dtype=mol._dtypes['insertion'])
mol.coords = np.array(np.atleast_3d(np.vstack(coords)), dtype=mol._dtypes['coords'])
mol.segid = np.array(segid, dtype=mol._dtypes['segid'])
mol.element = np.array(element, dtype=mol._dtypes['element'])
mol.occupancy = np.array(occupancy, dtype=mol._dtypes['occupancy'])
mol.beta = np.array(beta, dtype=mol._dtypes['beta'])
# mol.charge = np.array(charge, dtype=mol._dtypes['charge'])
# mol.record = np.array(record, dtype=mol._dtypes['record'])
return mol
示例3: _applyProteinCaps
# 需要导入模块: from htmd.molecule.molecule import Molecule [as 别名]
# 或者: from htmd.molecule.molecule.Molecule import resid [as 别名]
def _applyProteinCaps(mol, caps):
# AMBER capping
# =============
# This is the (horrible) way of adding caps in tleap:
# For now, this is hardwired for ACE and NME
# 1. Change one of the hydrogens of the N terminal (H[T]?[123]) to the ACE C atom, giving it a new resid
# 1a. If no hydrogen present, create the ACE C atom.
# 2. Change one of the oxygens of the C terminal ({O,OT1,OXT}) to the NME N atom, giving it a new resid
# 2a. If no oxygen present, create the NME N atom.
# 3. Reorder to put the new atoms first and last
# 4. Remove the lingering hydrogens of the N terminal and oxygens of the C terminal.
# Define the atoms to be replaced (0 and 1 corresponds to N- and C-terminal caps)
terminalatoms = {'ACE': 'H1 H2 H3 HT1 HT2 HT3', 'NME': 'OXT OT1 O'} # XPLOR names for H[123] and OXT are HT[123]
# and OT1, respectively.
capresname = ['ACE', 'NME']
capatomtype = ['C', 'N']
# For each caps definition
for seg in caps:
# Get the segment
segment = mol.atomselect('segid {}'.format(seg), indexes=True)
# Test segment
if len(segment) == 0:
raise RuntimeError('There is no segment {} in the molecule.'.format(seg))
if len(mol.atomselect('protein and segid {}'.format(seg), indexes=True)) == 0:
raise RuntimeError(
'Segment {} is not protein. Capping for non-protein segments is not supported.'.format(seg))
# For each cap
for i, cap in enumerate(caps[seg]):
if cap is None or (isinstance(cap, str) and cap == 'none'):
continue
# Get info on segment and its terminals
segment = mol.atomselect('segid {}'.format(seg), indexes=True)
resids = np.unique(mol.get('resid', sel=segment))
terminalids = [segment[0], segment[-1]]
terminalresids = [np.min(resids), np.max(resids)]
if i == 0:
orig_terminalresids = [np.min(resids), np.max(resids)]
# In case there is no cap defined
if cap is None or cap == '':
logger.warning(
'No cap provided for resid {} on segment {}. Did not apply it.'.format(terminalresids[i], seg))
continue
# If it is defined, test if supported
elif cap not in capresname:
raise RuntimeError(
'In segment {}, the {} cap is not supported. Try using {} instead.'.format(seg, cap, capresname))
# Test if cap is already applied
testcap = mol.atomselect('segid {} and resid "{}" and resname {}'.format(seg, terminalresids[i], cap),
indexes=True)
if len(testcap) != 0:
logger.warning('Cap {} already exists on segment {}. Did not re-apply it.'.format(cap, seg))
continue
# Test if the atom to change exists
termatomsids = mol.atomselect('segid {} and resid "{}" and name {}'.format(seg,
terminalresids[i],
terminalatoms[cap]),
indexes=True)
if len(termatomsids) == 0:
# Create new atom
termcaid = mol.atomselect('segid {} and resid "{}" and name CA'.format(seg, terminalresids[i]),
indexes=True)
termcenterid = mol.atomselect('segid {} and resid "{}" and name {}'.format(seg, terminalresids[i],
capatomtype[-i+1]),
indexes=True) # if i=0 => capatomtype[1]; i=1 => capatomtype[0]
atom = Molecule()
atom.empty(1)
atom.record = 'ATOM'
atom.name = capatomtype[i]
atom.resid = terminalresids[i]-1+2*i
atom.resname = cap
atom.segid = seg
atom.element = capatomtype[i]
atom.chain = np.unique(mol.get('chain', sel='segid {}'.format(seg)))
atom.coords = mol.coords[termcenterid] + 0.33 * np.subtract(mol.coords[termcenterid],
mol.coords[termcaid])
mol.insert(atom, terminalids[i])
# newatom = mol.numAtoms - 1
logger.info('In segment {}, resid {} had none of these atoms: {}. Capping was performed by creating '
'a new atom for cap construction by tleap.'.format(seg, terminalresids[i],
terminalatoms[cap]))
else:
# Select atom to change, do changes to cap, and change resid
newatom = np.max(termatomsids)
mol.set('resname', cap, sel=newatom)
mol.set('name', capatomtype[i], sel=newatom)
mol.set('element', capatomtype[i], sel=newatom)
mol.set('resid', terminalresids[i]-1+2*i, sel=newatom) # if i=0 => resid-1; i=1 => resid+1
# Reorder
neworder = np.arange(mol.numAtoms)
neworder[newatom] = terminalids[i]
neworder[terminalids[i]] = newatom
_reorderMol(mol, neworder)
# For each cap
for i, cap in enumerate(caps[seg]):
if cap is None or (isinstance(cap, str) and cap == 'none'):
#.........这里部分代码省略.........
示例4: ionizePlace
# 需要导入模块: from htmd.molecule.molecule import Molecule [as 别名]
# 或者: from htmd.molecule.molecule.Molecule import resid [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.')
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.record = 'ATOM'
atom.chain = 'I'
atom.segid = 'I'
atom.occupancy = 0
atom.beta = 0
atom.insertion = ''
atom.element = ''
atom.altloc = ''
for i in range(nanion):
atom.name = anionatom
atom.resname = anion
atom.resid = newmol.resid[-1] + 1
atom.coords = waterpos[randidx[i], :]
newmol.insert(atom, len(newmol.name))
for i in range(ncation):
atom.name = cationatom
atom.resname = cation
atom.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
示例5: _applyProteinCaps
# 需要导入模块: from htmd.molecule.molecule import Molecule [as 别名]
# 或者: from htmd.molecule.molecule.Molecule import resid [as 别名]
def _applyProteinCaps(mol, caps):
# AMBER capping
# =============
# This is the (horrible) way of adding caps in tleap:
# For now, this is hardwired for ACE and NME
# 1. Change one of the hydrogens of the N terminal (H[T]?[123]) to the ACE C atom, giving it a new resid
# 1a. If no hydrogen present, create the ACE C atom.
# 2. Change one of the oxygens of the C terminal ({O,OT1,OXT}) to the NME N atom, giving it a new resid
# 2a. If no oxygen present, create the NME N atom.
# 3. Reorder to put the new atoms first and last
# 4. Remove the lingering hydrogens of the N terminal and oxygens of the C terminal.
# Define the atoms to be replaced (0 and 1 corresponds to N- and C-terminal caps)
terminalatoms = {'ACE': ['H1', 'H2', 'H3', 'HT1', 'HT2', 'HT3'], 'NME': ['OXT', 'OT1', 'O']} # XPLOR names for H[123] and OXT are HT[123]
# and OT1, respectively.
capresname = ['ACE', 'NME']
capatomtype = ['C', 'N']
# For each caps definition
for seg in caps:
prot = mol.atomselect('protein') # Can't move this out since we remove atoms in this loop
# Get the segment
segment = np.where(mol.segid == seg)[0]
# Test segment
if len(segment) == 0:
raise RuntimeError('There is no segment {} in the molecule.'.format(seg))
if not np.any(prot & (mol.segid == seg)):
raise RuntimeError('Segment {} is not protein. Capping for non-protein segments is not supported.'.format(seg))
# For each cap
passed = False
for i, cap in enumerate(caps[seg]):
if cap is None or (isinstance(cap, str) and cap == 'none'):
continue
# Get info on segment and its terminals
segidm = mol.segid == seg # Mask for segid
segididx = np.where(segidm)[0]
resids = mol.resid[segididx]
terminalids = [segididx[0], segididx[-1]]
terminalresids = [resids[0], resids[-1]]
residm = mol.resid == terminalresids[i] # Mask for resid
if not passed:
orig_terminalresids = terminalresids
passed = True
if cap is None or cap == '': # In case there is no cap defined
logger.warning('No cap provided for resid {} on segment {}. Did not apply it.'.format(terminalresids[i], seg))
continue
elif cap not in capresname: # If it is defined, test if supported
raise RuntimeError('In segment {}, the {} cap is not supported. Try using {} instead.'.format(seg, cap, capresname))
# Test if cap is already applied
testcap = np.where(segidm & residm & (mol.resname == cap))[0]
if len(testcap) != 0:
logger.warning('Cap {} already exists on segment {}. Did not re-apply it.'.format(cap, seg))
continue
# Test if the atom to change exists
termatomsids = np.zeros(residm.shape, dtype=bool)
for atm in terminalatoms[cap]:
termatomsids |= mol.name == atm
termatomsids = np.where(termatomsids & segidm & residm)[0]
if len(termatomsids) == 0:
# Create new atom
termcaid = np.where(segidm & residm & (mol.name == 'CA'))[0]
termcenterid = np.where(segidm & residm & (mol.name == capatomtype[1-i]))[0]
atom = Molecule()
atom.empty(1)
atom.record = np.array(['ATOM'], dtype=Molecule._dtypes['record'])
atom.name = np.array([capatomtype[i]], dtype=Molecule._dtypes['name'])
atom.resid = np.array([terminalresids[i]-1+2*i], dtype=Molecule._dtypes['resid'])
atom.resname = np.array([cap], dtype=Molecule._dtypes['resname'])
atom.segid = np.array([seg], dtype=Molecule._dtypes['segid'])
atom.element = np.array([capatomtype[i]], dtype=Molecule._dtypes['element'])
atom.chain = np.array([np.unique(mol.chain[segidm])], dtype=Molecule._dtypes['chain']) # TODO: Assumption of single chain in a segment might be wrong
atom.coords = mol.coords[termcenterid] + 0.33 * np.subtract(mol.coords[termcenterid],
mol.coords[termcaid])
mol.insert(atom, terminalids[i])
# logger.info('In segment {}, resid {} had none of these atoms: {}. Capping was performed by creating '
# 'a new atom for cap construction by tleap.'.format(seg, terminalresids[i],
# ' '.join(terminalatoms[cap])))
else:
# Select atom to change, do changes to cap, and change resid
newatom = np.max(termatomsids)
mol.set('resname', cap, sel=newatom)
mol.set('name', capatomtype[i], sel=newatom)
mol.set('element', capatomtype[i], sel=newatom)
mol.set('resid', terminalresids[i]-1+2*i, sel=newatom) # if i=0 => resid-1; i=1 => resid+1
# Reorder
neworder = np.arange(mol.numAtoms)
neworder[newatom] = terminalids[i]
neworder[terminalids[i]] = newatom
_reorderMol(mol, neworder)
# For each cap
for i, cap in enumerate(caps[seg]):
#.........这里部分代码省略.........