Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from chempy import fragments, feedback, models
cycles, state, quiet = int(cycles), int(state), int(quiet)
# suppress feedback for model merging
feedback['actions'] = False
# work with named selection
namedsele = cmd.get_unused_name('_')
cmd.select(namedsele, '{} & present'.format(selection), 0)
identifiers = []
cmd.iterate(namedsele + ' and polymer and guide and alt +A',
'identifiers.append([segi,chain,resi,resv,resn])', space=locals())
model = models.Indexed()
for (segi,chain,resi,resv,resn) in identifiers:
try:
fname = resn.lower() if resn != 'MSE' else 'met'
frag = fragments.get(fname)
except IOError:
print(' Warning: unknown residue: ' + resn)
continue
for a in frag.atom:
a.segi = segi
a.chain = chain
a.resi = resi
a.resi_number = resv
a.resn = resn
model.merge(frag)
def _create_molecule(n, mydata, resolution, created):
model = models.Indexed()
name = _get_molecule_name(n.get_name(), resolution)
if name in created:
name = name + "-2"
print n, name, resolution
th = RMF.TraverseHelper(n, name, resolution)
created[name] = (th, model)
print "creating molecule", name
cgol = []
_create_atoms(th, mydata, model, cgol, created)
frame = n.get_file().get_current_frame().get_index() + 1
if len(cgol) > 0:
print cgol
cmd.load_cgo(cgol, name + "-graphics", frame)
continue
elif byte <= 0x7f:
# LABEL
read_label()
xyz = read_xyz()
survey.label(xyz, byte & 0x3f)
elif byte <= 0xbf:
# LINE
read_label()
xyz = read_xyz()
survey.line(xyz)
elif byte <= 0xff:
# Reserved
continue
model = models.Indexed()
for (xyz,s) in survey.items():
l0, _, l1 = s.labels[0].rpartition('.')
resi, name = l1[:5], l1[5:]
segi, chain, resn = l0[-8:-4], l0[-4:-3], l0[-3:]
atom = Atom()
atom.coord = [i/100.0 for i in xyz]
atom.segi = segi
atom.chain = chain
atom.resn = resn
atom.name = name
atom.resi = resi
atom.b = atom.coord[2]
atom.label = s.labels[0]
if s.lrud is not None:
atom.vdw = sum(s.lrud)/400.0
model.add_atom(atom)
# jen to zaskrtnute
generatedString = ""
for key in self.s:
if self.s[key].get() == 1:
# pak pouzit do vyberu:
if key == "AA":
generatedString = generatedString + "+" + self.stdamString
else:
generatedString = generatedString + "+" + key
generatedString = generatedString[1:]
print("Checked: " + generatedString)
mmodel = cmd.get_model(self.whichModelSelect)
print(self.whichModelSelect + " asize: " + str(len(mmodel.atom)))
newmodel = Indexed()
for matom in mmodel.atom:
if generatedString.find(matom.resn) > -1:
# print matom.resn
newmodel.atom.append(matom)
cmd.load_model(newmodel, "tmpCaverModel")
# cmd.label("example","name")
# fix outdir slashes
outdir = outdir.replace("\\", "/")
if (outdir.endswith("/")):
outdir = outdir[:-1]
input = "%s/out.pdb" % (outdir)
# cmd.save(input, self.whichModelSelect) # to by ulozilo cely model whichModelSelect.
cmd.save(input, "tmpCaverModel")
cmd.delete("tmpCaverModel")
cesta = os.getcwd()
# set ignore waters to false -- the model is already filtered by input model and aminos
atmap = dict()
if method in ['bahar1996', '1', 1]:
modelAll = cmd.get_model('(%s) and resn %s' % (selection, '+'.join(sidechaincenteratoms)))
for at in modelAll.atom:
if at.name in sidechaincenteratoms[at.resn]:
atmap.setdefault((at.segi, at.chain, at.resn, at.resi), []).append(at)
elif method in ['centroid', '2', 2]:
modelAll = cmd.get_model('(%s) and polymer and not (hydro or name C+N+O)' % selection)
for at in modelAll.atom:
atmap.setdefault((at.segi, at.chain, at.resn, at.resi), []).append(at)
else:
print('Error: unknown method:', method)
raise CmdException
model = models.Indexed()
for centeratoms in atmap.values():
center = cpv.get_null()
for at in centeratoms:
center = cpv.add(center, at.coord)
center = cpv.scale(center, 1./len(centeratoms))
atom = Atom()
atom.coord = center
atom.index = model.nAtom + 1
atom.name = name
for key in ['resn','chain','resi','resi_number','hetatm','ss','segi']:
atom.__dict__[key] = at.__dict__[key]
model.add_atom(atom)
model.update_index()
if object in cmd.get_object_list():
cmd.delete(object)
cmd.load_model(model, object)
def removewater(self, selection='(all)'):
seloutwater = Indexed()
for a in selection.atom:
if (a.resn != "HOH") and (a.resn != "H2O") and (a.resn != "WAT"):
seloutwater.atom.append(a)
return seloutwater