How to add chain id in pdb - python

By using biopython library, I would like to add chains ids in my pdb file.
I'm using
p = PDBParser()
structure=p.get_structure('mypdb',mypdb.pdb)
model=structure[0]
model.child_list=["A","B"]
But I got this error:
Traceback (most recent call last):
File "../../principal_axis_v3.py", line 319, in <module>
main()
File "../../principal_axis_v3.py", line 310, in main
protA=read_PDB(struct,ch1,s1,e1)
File "../../principal_axis_v3.py", line 104, in read_PDB
chain=model[ch]
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Bio/PDB/Entity.py", line 38, in __getitem__
return self.child_dict[id]
KeyError: 'A'
I tried to changes the keys in th child.dict, butI got another error:
Traceback (most recent call last):
File "../../principal_axis_v3.py", line 319, in <module>
main()
File "../../principal_axis_v3.py", line 310, in main
protA=read_PDB(struct,ch1,s1,e1)
File "../../principal_axis_v3.py", line 102, in read_PDB
model.child_dict.keys=["A","B"]
AttributeError: 'dict' object attribute 'keys' is read-only
How can I add chains ids ?

Your error is that child_list is not a list with chain IDs, but of Chain objects (Bio.PDB.Chain.Chain). You have to create Chain objects and then add them to the structure. A lame example:
from Bio.PDB.Chain import Chain
my_chain = Chain("C")
model.add(my_chain)
Now you can access the model child_dict:
>>> model.child_dict
{'A': <Chain id=A>, 'C': <Chain id=C>}
>>> model.child_dict["C"]
<Chain id=C>

Related

AttributeErrors when adding variables/constraints to Gurobi persistent

I am trying to modify a model by adding variables/constraints and re-solving the updated model, following the guide.
The problem is that both cases fail with attribute errors, for a variable:
Traceback (most recent call last):
File "seqdesign.py", line 98, in <module>
main()
File "seqdesign.py", line 71, in main
problem._solver.add_var(problem._model.McBernoulliTrials)
File "/home/edo/miniconda3/envs/spacers/lib/python3.7/site-packages/pyomo/solvers/plugins/solvers/persistent_solver.py", line 153, in add_var
self._add_var(var)
File "/home/edo/miniconda3/envs/spacers/lib/python3.7/site-packages/pyomo/solvers/plugins/solvers/gurobi_direct.py", line 208, in _add_var
vtype = self._gurobi_vtype_from_var(var)
File "/home/edo/miniconda3/envs/spacers/lib/python3.7/site-packages/pyomo/solvers/plugins/solvers/gurobi_direct.py", line 377, in _gurobi_vtype_from_var
if var.is_binary():
AttributeError: 'IndexedVar' object has no attribute 'is_binary'
And for a constraint:
Traceback (most recent call last):
File "seqdesign.py", line 98, in <module>
main()
File "seqdesign.py", line 71, in main
problem._solver.add_constraint(problem._model.McBernoulliTrialsSetPositive)
File "/home/edo/miniconda3/envs/spacers/lib/python3.7/site-packages/pyomo/solvers/plugins/solvers/persistent_solver.py", line 132, in add_constraint
self._add_constraint(con)
File "/home/edo/miniconda3/envs/spacers/lib/python3.7/site-packages/pyomo/solvers/plugins/solvers/gurobi_direct.py", line 272, in _add_constraint
if is_fixed(con.body):
AttributeError: 'IndexedConstraint' object has no attribute 'body'
Is the problem that I am using indexed variables and constraints? How to make this work without migrating all code from pyomo.environ to pyomo.core?
You cannot pass an IndexedVar or and IndexedConstraint into the add_var and add_constraint methods. You have to loop over the individual variables and constraints and add them one at a time:
for v in my_var.values():
solver.add_var(v)
for c in my_con.values():
solver.add_constraint(c)
Additionally, you can check if a variable or constraint is indexed with my_var.is_indexed() or my_con.is_indexed().

Populate Mongo Database with Json file in Python Script from command Line

page = open("npm.json", "r")
parsed = json.loads(page.read())
for i in parsed["dependencies"]:
collection.insert_one(i)
Hi, I am trying to read in a json file and populate my mongoDB with the rows called ependencies.it keeps giving me and error. I have tried insert, insert_one &insert_many to no avail.
The following is the error i get
File "database.py", line 43, in <module>
collection.insert_one(i)
File "/usr/local/lib/python3.6/dist-packages/pymongo/collection.py", line 684, in insert_one
common.validate_is_document_type("document", document)
File "/usr/local/lib/python3.6/dist-packages/pymongo/common.py", line 453, in validate_is_document_type
"collections.MutableMapping" % (option,))
TypeError: document must be an instance of dict, bson.son.SON, bson.raw_bson.RawBSONDocument, or a type that inherits from collections.MutableMapping
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
import apport.fileutils
File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
from apport.packaging_impl import impl as packaging
File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 23, in <module>
import apt
File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
Original exception was:
Traceback (most recent call last):
File "database.py", line 43, in <module>
collection.insert_one(i)
File "/usr/local/lib/python3.6/dist-packages/pymongo/collection.py", line 684, in insert_one
common.validate_is_document_type("document", document)
File "/usr/local/lib/python3.6/dist-packages/pymongo/common.py", line 453, in validate_is_document_type
"collections.MutableMapping" % (option,))
TypeError: document must be an instance of dict, bson.son.SON, bson.raw_bson.RawBSONDocument, or a type that inherits from collections.MutableMapping
The json file is a list of node dependencies. i ran the command npm list on a node project. Can anybody help Thanks in advance
It looks like your data in dependencies is a dictionary. This means when you iterate over it, you will get strings (which are the keys in this case).
An example would be like so:
my_entry = {'a': 1, 'b': 2}
for i in myentry:
print(i)
# will print 'a' then 'b', not 1 then 2
I'm assuming each dependency is a key, and you want to insert the value. So
# dictionary.values() will give you just the values
for v in parsed['dependencies'].values():
if isinstance(v, dict):
collection.insert_one(v)
else:
raise ValueError("object is not dictionary")
Mongo will only take json or bson entries, which are like dictionaries. When you pass keys, you are trying to insert objects of type string, which it doesn't support

How to delete ADUser using Python pyad module

I'm having a problem with deleting ADUser.
pyad.set_defaults(ldap_server="dc1.domain.com", username="service_account", password="mypassword")
user = aduser.ADUser.from_dn("cn=myuser, ou=staff, dc=domain, dc=com")
user.delete()
Unfortunately I could not figure out how to format this text to look like a real traceback
Traceback (most recent call last):
File "C:/Automation/qa/robot2/python_lib/keywords/AD/unittest.py", line 34,
in <module>
ad_connect.bg_ad_user_remove(user_login='vasya.oconnor#test-acme.com',dn_string= dn_string)
File "C:\Automation\qa\robot2\python_lib\keywords\AD\_bg_ad_general.py", line 156, in bg_ad_user_remove
user.delete()
File "C:\Python27\lib\site-packages\pyad\adobject.py", line 537, in delete
if not parent:
File "C:\Python27\lib\site-packages\future\types\newobject.py", line 90, in __nonzero__
return type(self).__len__(self)
AttributeError: type object 'ADContainer' has no attribute '__len__'

fail to setup openstack dynamic inventory

I am trying to setup openstack dynamic inventory,when I am trying execute this command it's throwing me this error.
command: etc/ansible/hosts --list
Traceback (most recent call last):
File "/etc/ansible/hosts", line 263, in <module>
main()
File "/etc/ansible/hosts", line 249, in main
inventory = shade.inventory.OpenStackInventory(**inventory_args)
File "/usr/local/lib/python2.7/dist-packages/shade/inventory.py", line 35, in __init__
config_files=os_client_config.config.CONFIG_FILES + config_files)
File "/usr/local/lib/python2.7/dist-packages/os_client_config/config.py", line 221, in __init__
self.cloud_config['clouds'] = {}
TypeError: list indices must be integers, not str

what is the replacement of wikipedia.getSite()? or is it still usable?

I ran a pywikibot sample code,
but it is aborted due to AttributeError.
Traceback is ...
Traceback (most recent call last):
File "pwb.py", line 270, in <module>
if not main():
File "pwb.py", line 264, in main
run_python_file(filename, [filename] + args, argvu, file_package)
File "pwb.py", line 109, in run_python_file
main_mod.__dict__)
File ".\cochonBot.py", line 81, in <module>
main()
File ".\cochonBot.py", line 52, in main
stub_list = cat_list_rec(u'遺꾨쪟:?좊쭑湲 遺꾨쪟', stub_ignore_cats)
File ".\cochonBot.py", line 14, in cat_list_rec
cat = catlib.Category(wikipedia.getSite(), top_cat)
AttributeError: 'module' object has no attribute 'getSite'
<type 'exceptions.AttributeError'>
CRITICAL: Waiting for 1 network thread(s) to finish. Press ctrl-c to abort
what is the replacement of wikipedia.getSite()? or is it still usable?
You can simply use pywikibot.Site() instead.

Categories

Resources