Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make fragment compatible for rms #216

Merged
merged 8 commits into from
Oct 17, 2023
31 changes: 26 additions & 5 deletions src/Parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,22 @@ getatomdictsmiles(smiles) = getatomdictfromrdkit(Chem.AddHs(Chem.MolFromSmiles(s
export getatomdictsmiles
getatomdictinchi(inchi) = getatomdictfromrdkit(Chem.AddHs(Chem.MolFromInchi(inchi)))
export getatomdictinchi
getatomdictadjlist(adjlist) = getatomdictfromrmg(molecule.Molecule().from_adjacency_list(adjlist))
function getatomdictadjlist(adjlist)
_ , cutting_label_list = fragment.Fragment().detect_cutting_label(adjlist)
if isempty(cutting_label_list)
mol = molecule.Molecule().from_adjacency_list(adjlist)
else
mol = fragment.Fragment().from_adjacency_list(adjlist)
end
if pybuiltin(:isinstance)(mol, molecule.Molecule)
getatomdictfromrmg(mol)
elseif pybuiltin(:isinstance)(mol, fragment.Fragment)
mol.assign_representative_molecule()
getatomdictfromrmg(mol.mol_repr)
else
@error("Unrecognizable molecule type $mol")
end
end
export getatomdictadjlist

function getspeciesradius(atomdict,nbonds::Int64)
Expand Down Expand Up @@ -290,19 +305,25 @@ function readinputyml(fname::String)
if "adjlist" in keys(d)
try
d["atomnums"],d["bondnum"],d["molecularweight"] = getatomdictadjlist(d["adjlist"])
catch
@warn("failed to generate molecular information from smiles for species $spcname")
catch e
showerror(stdout, e)
display(stacktrace(catch_backtrace()))
@warn("failed to generate molecular information from adjlist for species $spcname")
end
elseif "smiles" in keys(d)
try
d["atomnums"],d["bondnum"],d["molecularweight"] = getatomdictsmiles(d["smiles"])
catch
catch e
showerror(stdout, e)
display(stacktrace(catch_backtrace()))
@warn("failed to generate molecular information from smiles for species $spcname")
end
elseif "inchi" in keys(d)
try
d["atomnums"],d["bondnum"],d["molecularweight"] = getatomdictinchi(d["inchi"])
catch
catch e
showerror(stdout, e)
display(stacktrace(catch_backtrace()))
@warn("failed to generate molecular information from inchi for species $spcname")
end
end
Expand Down
3 changes: 3 additions & 0 deletions src/ReactionMechanismSimulator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module ReactionMechanismSimulator
const Chem = PyNULL()
const Desc = PyNULL()
const molecule = PyNULL()
const fragment = PyNULL()
const pydot = PyNULL()
const chemkin =PyNULL()
const species = PyNULL()
Expand All @@ -29,6 +30,7 @@ module ReactionMechanismSimulator
copy!(falloff,pyimport("rmgpy.kinetics.falloff"))
copy!(chebyshev,pyimport("rmgpy.kinetics.chebyshev"))
copy!(solvation,pyimport("rmgpy.data.solvation"))
copy!(fragment,pyimport("rmgpy.molecule.fragment"))
catch e
copy!(molecule,pyimport_conda("molecule.molecule","rmgmolecule","hwpang"))
copy!(chemkin,pyimport_conda("molecule.chemkin","rmgmolecule","hwpang"))
Expand All @@ -40,6 +42,7 @@ module ReactionMechanismSimulator
copy!(falloff,pyimport_conda("molecule.kinetics.falloff","rmgmolecule","hwpang"))
copy!(chebyshev,pyimport_conda("molecule.kinetics.chebyshev","rmgmolecule","hwpang"))
copy!(solvation,pyimport_conda("molecule.data.solvation","rmgmolecule","hwpang"))
copy!(fragment,pyimport_conda("molecule.molecule.fragment","rmgmolecule","hwpang"))
end
copy!(pydot,pyimport_conda("pydot","pydot"))
copy!(os,pyimport_conda("os","os"))
Expand Down
2 changes: 1 addition & 1 deletion src/Simulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ end
function rops(ssys::SystemSimulation, name, t)
domains = getfield.(ssys.sims, :domain)
ind = findfirst(isequal(name), ssys.names)
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)])
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)]))
mjohnson541 marked this conversation as resolved.
Show resolved Hide resolved
Nspcs = sum([length(getphasespecies(sim.domain.phase)) for sim in ssys.sims])
cstot = zeros(Nspcs)
vns = Array{Any,1}(undef, length(domains))
Expand Down
13 changes: 11 additions & 2 deletions src/fluxdiagrams.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,20 @@ function drawspc(spc::Species,path::String=".")
end
end
if spc.adjlist != ""
mol = molecule.Molecule().from_adjacency_list(spc.adjlist)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do this one with Species the same way you do later?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep! Done.

_ , cutting_label_list = fragment.Fragment().detect_cutting_label(spc.adjlist)
if isempty(cutting_label_list)
mol = molecule.Molecule().from_adjacency_list(spc.adjlist)
else
mol = fragment.Fragment().from_adjacency_list(spc.adjlist)
end
elseif spc.inchi != ""
mol = molecule.Molecule().from_inchi(spc.inchi)
elseif spc.smiles != ""
mol = molecule.Molecule().from_smiles(spc.smiles)
if occursin(r"R", spc.smiles) || occursin(r"L", spc.smiles)
mol = fragment.Fragment().from_smiles_like_string(spc.smiles)
else
mol = molecule.Molecule().from_smiles(spc.smiles)
end
else
throw(error("no smiles or inchi for molecule $name"))
end
Expand Down
3 changes: 3 additions & 0 deletions src/rmstest.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
using PyCall
const Chem = PyNULL()
const molecule = PyNULL()
const fragment = PyNULL()
const pydot = PyNULL()
copy!(Chem,pyimport_conda("rdkit.Chem","rdkit","rmg"))
try
copy!(molecule, pyimport("rmgpy.molecule"))
copy!(fragment, pyimport("rmgpy.molecule.fragment"))
catch e
copy!(molecule, pyimport_conda("molecule.molecule", "rmgmolecule", "hwpang"))
copy!(fragment, pyimport_conda("molecule.molecule.fragment", "rmgmolecule", "hwpang"))
end
copy!(pydot,pyimport_conda("pydot","pydot","rmg"))

Expand Down
Loading