Skip to content

Commit 49f8d1a

Browse files
authored
Merge pull request #216 from lily90502/frag_draw
make fragment compatible for rms
2 parents 02b73d0 + 5459c28 commit 49f8d1a

File tree

5 files changed

+44
-8
lines changed

5 files changed

+44
-8
lines changed

src/Parse.jl

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,22 @@ getatomdictsmiles(smiles) = getatomdictfromrdkit(Chem.AddHs(Chem.MolFromSmiles(s
165165
export getatomdictsmiles
166166
getatomdictinchi(inchi) = getatomdictfromrdkit(Chem.AddHs(Chem.MolFromInchi(inchi)))
167167
export getatomdictinchi
168-
getatomdictadjlist(adjlist) = getatomdictfromrmg(molecule.Molecule().from_adjacency_list(adjlist))
168+
function getatomdictadjlist(adjlist)
169+
_ , cutting_label_list = fragment.Fragment().detect_cutting_label(adjlist)
170+
if isempty(cutting_label_list)
171+
mol = molecule.Molecule().from_adjacency_list(adjlist)
172+
else
173+
mol = fragment.Fragment().from_adjacency_list(adjlist)
174+
end
175+
if pybuiltin(:isinstance)(mol, molecule.Molecule)
176+
getatomdictfromrmg(mol)
177+
elseif pybuiltin(:isinstance)(mol, fragment.Fragment)
178+
mol.assign_representative_molecule()
179+
getatomdictfromrmg(mol.mol_repr)
180+
else
181+
@error("Unrecognizable molecule type $mol")
182+
end
183+
end
169184
export getatomdictadjlist
170185

171186
function getspeciesradius(atomdict,nbonds::Int64)
@@ -290,19 +305,25 @@ function readinputyml(fname::String)
290305
if "adjlist" in keys(d)
291306
try
292307
d["atomnums"],d["bondnum"],d["molecularweight"] = getatomdictadjlist(d["adjlist"])
293-
catch
294-
@warn("failed to generate molecular information from smiles for species $spcname")
308+
catch e
309+
showerror(stdout, e)
310+
display(stacktrace(catch_backtrace()))
311+
@warn("failed to generate molecular information from adjlist for species $spcname")
295312
end
296313
elseif "smiles" in keys(d)
297314
try
298315
d["atomnums"],d["bondnum"],d["molecularweight"] = getatomdictsmiles(d["smiles"])
299-
catch
316+
catch e
317+
showerror(stdout, e)
318+
display(stacktrace(catch_backtrace()))
300319
@warn("failed to generate molecular information from smiles for species $spcname")
301320
end
302321
elseif "inchi" in keys(d)
303322
try
304323
d["atomnums"],d["bondnum"],d["molecularweight"] = getatomdictinchi(d["inchi"])
305-
catch
324+
catch e
325+
showerror(stdout, e)
326+
display(stacktrace(catch_backtrace()))
306327
@warn("failed to generate molecular information from inchi for species $spcname")
307328
end
308329
end

src/ReactionMechanismSimulator.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module ReactionMechanismSimulator
44
const Chem = PyNULL()
55
const Desc = PyNULL()
66
const molecule = PyNULL()
7+
const fragment = PyNULL()
78
const pydot = PyNULL()
89
const chemkin =PyNULL()
910
const species = PyNULL()
@@ -29,6 +30,7 @@ module ReactionMechanismSimulator
2930
copy!(falloff,pyimport("rmgpy.kinetics.falloff"))
3031
copy!(chebyshev,pyimport("rmgpy.kinetics.chebyshev"))
3132
copy!(solvation,pyimport("rmgpy.data.solvation"))
33+
copy!(fragment,pyimport("rmgpy.molecule.fragment"))
3234
catch e
3335
copy!(molecule,pyimport_conda("molecule.molecule","rmgmolecule","hwpang"))
3436
copy!(chemkin,pyimport_conda("molecule.chemkin","rmgmolecule","hwpang"))
@@ -40,6 +42,7 @@ module ReactionMechanismSimulator
4042
copy!(falloff,pyimport_conda("molecule.kinetics.falloff","rmgmolecule","hwpang"))
4143
copy!(chebyshev,pyimport_conda("molecule.kinetics.chebyshev","rmgmolecule","hwpang"))
4244
copy!(solvation,pyimport_conda("molecule.data.solvation","rmgmolecule","hwpang"))
45+
copy!(fragment,pyimport_conda("molecule.molecule.fragment","rmgmolecule","hwpang"))
4346
end
4447
copy!(pydot,pyimport_conda("pydot","pydot"))
4548
copy!(os,pyimport_conda("os","os"))

src/Simulation.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ end
319319
function rops(ssys::SystemSimulation, name, t)
320320
domains = getfield.(ssys.sims, :domain)
321321
ind = findfirst(isequal(name), ssys.names)
322-
Nrxns = sum([length(sim.domain.phase.reactions) for sim in ssys.sims]) + sum([length(inter.reactions) for inter in ssys.interfaces if hasproperty(inter, :reactions)])
322+
Nrxns = sum([length(sim.domain.phase.reactions) for sim in ssys.sims]) + sum(Vector{Int}([length(inter.reactions) for inter in ssys.interfaces if hasproperty(inter, :reactions)]))
323323
Nspcs = sum([length(getphasespecies(sim.domain.phase)) for sim in ssys.sims])
324324
cstot = zeros(Nspcs)
325325
vns = Array{Any,1}(undef, length(domains))

src/fluxdiagrams.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,20 @@ function drawspc(spc::Species,path::String=".")
4242
end
4343
end
4444
if spc.adjlist != ""
45-
mol = molecule.Molecule().from_adjacency_list(spc.adjlist)
45+
_ , cutting_label_list = fragment.Fragment().detect_cutting_label(spc.adjlist)
46+
if isempty(cutting_label_list)
47+
mol = molecule.Molecule().from_adjacency_list(spc.adjlist)
48+
else
49+
mol = fragment.Fragment().from_adjacency_list(spc.adjlist)
50+
end
4651
elseif spc.inchi != ""
4752
mol = molecule.Molecule().from_inchi(spc.inchi)
4853
elseif spc.smiles != ""
49-
mol = molecule.Molecule().from_smiles(spc.smiles)
54+
if occursin(r"R", spc.smiles) || occursin(r"L", spc.smiles)
55+
mol = fragment.Fragment().from_smiles_like_string(spc.smiles)
56+
else
57+
mol = molecule.Molecule().from_smiles(spc.smiles)
58+
end
5059
else
5160
throw(error("no smiles or inchi for molecule $name"))
5261
end

src/rmstest.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
using PyCall
22
const Chem = PyNULL()
33
const molecule = PyNULL()
4+
const fragment = PyNULL()
45
const pydot = PyNULL()
56
copy!(Chem,pyimport_conda("rdkit.Chem","rdkit","rmg"))
67
try
78
copy!(molecule, pyimport("rmgpy.molecule"))
9+
copy!(fragment, pyimport("rmgpy.molecule.fragment"))
810
catch e
911
copy!(molecule, pyimport_conda("molecule.molecule", "rmgmolecule", "hwpang"))
12+
copy!(fragment, pyimport_conda("molecule.molecule.fragment", "rmgmolecule", "hwpang"))
1013
end
1114
copy!(pydot,pyimport_conda("pydot","pydot","rmg"))
1215

0 commit comments

Comments
 (0)