Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F61056381
test1.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, May 4, 06:24
Size
3 KB
Mime Type
text/x-python
Expires
Mon, May 6, 06:24 (2 d)
Engine
blob
Format
Raw Data
Handle
17458915
Attached To
rTWTEST master_thesis_Lee
test1.py
View Options
import
sys
sys
.
path
.
insert
(
0
,
'C:\envipath_code'
)
from
enviPath_python.enviPath
import
*
from
enviPath_python.objects
import
*
import
rdkit
from
rdkit
import
Chem
from
rdkit.Chem.MolStandardize
import
rdMolStandardize
from
rdkit.Chem
import
Descriptors
from
rdkit.Chem.rdMolDescriptors
import
CalcMolFormula
INSTANCE_HOST
=
'https://envipath.org'
eP
=
enviPath
(
INSTANCE_HOST
)
ep
.
login
(
'leetseng'
,
'Joan1388'
)
def
main
():
package_id
=
'https://envipath.org/package/4a3cd0f4-4d2b-4f00-b3e6-a29e721f7038'
sludge
=
Package
(
eP
.
requester
,
id
=
package_id
)
compounds
=
sludge
.
get_compounds
()
# get the list of compounds
analyze_compounds
(
compounds
,
"ouputfile.txt"
)
def
canonicalize_smiles
(
smiles
):
mol
=
Chem
.
MolFromSmiles
(
smiles
)
# creates mol object from SMILES
uncharger
=
rdMolStandardize
.
Uncharger
()
# easier to access
uncharged
=
uncharger
.
uncharge
(
mol
)
# protonates or deprotonates the mol object
new_smiles
=
rdkit
.
Chem
.
rdmolfiles
.
MolToSmiles
(
uncharged
)
# converts mol object to canonical SMILES
can_smiles
=
Chem
.
CanonSmiles
(
new_smiles
)
return
can_smiles
def
analyze_compounds
(
all_compounds
,
output_filename
):
header
=
'{}
\t
{}
\t
{}
\t
{}
\t
{}
\t
{}
\t
{}
\t
{}
\t
{}
\n
'
.
format
(
'Index'
,
'Name'
,
'ID'
,
'Full_SMILES'
,
'Cropped_SMILES'
,
'Is_compoiste'
,
'Canonical_SMILES'
,
'Cropped_canonical_SMILES'
,
'Number_halflives'
)
outfile
=
open
(
output_filename
,
'w'
)
outfile
.
write
(
header
)
#
sludge
=
Package
(
eP
.
requester
,
id
=
package_id
)
scenarios
=
sludge
.
get_scenarios
()
i
=
0
for
scen
in
scenarios
:
# is_composite = False
i
+=
1
print
(
"Hello, I am compound #"
,
i
)
# compound = Compound(eP.requester, id=cpd.get_id())
# cpd_structure = CompoundStructure(eP.requester, id=cpd.get_id())
# cpd_structure.get_scenarios()
name
=
compound
.
get_name
()
id
=
compound
.
get_id
()
print
(
id
)
try
:
# halflifes = cpd_structure.get_halflifes()
scen
=
cpd_structure
.
get_scenarios
()
except
:
continue
full_smiles
=
compound
.
get_smiles
()
canonical_smiles
=
canonicalize_smiles
(
full_smiles
)
cropped_smiles
=
full_smiles
if
'.'
in
full_smiles
:
is_compoiste
=
True
cropped_smiles
=
full_smiles
.
split
(
'.'
)[
0
]
cropped_canonical_smiles
=
canonicalize_smiles
(
cropped_smiles
)
data_list
=
'{}
\t
{}
\t
{}
\t
{}
\t
{}
\t
{}
\t
{}
\t
{}
\t
{}
\n
'
.
format
(
i
,
name
,
id
,
full_smiles
,
cropped_smiles
,
is_composite
,
canonical_smiles
,
cropped_canonical_smiles
,
len
(
halflifes
))
outfile
.
write
(
data_list
)
outfile
.
close
()
main
()
# #How many cpd/reaction/scenario?
#
# print('Number of compounds:', len(compounds))
# print(compounds[0])
# compound1 = compounds[0]
# print(compound1.get_id())
# scenario1 = full_compound1.get_scenarios()
# print(scenario1)
full_compound1
=
CompoundStructure
(
eP
.
requester
,
id
=
'https://envipath.org/package/4a3cd0f4-4d2b-4f00-b3e6-a29e721f7038/scenario/42f1c95b-2d26-42a8-9bab-691ea20968e8'
)
#load the object of compound or reaction or scenarios
# hf1 = full_compound1.get_halflifes()
reaction1
=
full_compound1
.
get_reactions
()[
0
]
# print(hf1)
print
(
reaction1
.
get_name
())
Event Timeline
Log In to Comment