Skip to content

Commit

Permalink
molecule tables updated
Browse files Browse the repository at this point in the history
  • Loading branch information
bhavin2897 committed Dec 18, 2023
1 parent 168f97a commit 4dac2a1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
3 changes: 0 additions & 3 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions ckanext/rdkit_visuals/models/molecule_rel.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
from sqlalchemy.orm import relationship
from sqlalchemy import orm

from ckan.model import meta, Package, domain_object
import ckan.model.package as _package
from ckanext.rdkit_visuals.models.molecule_tab import Molecules
from sqlalchemy import types as _types
from ckan.model import Session
from ckan.model import meta
#from ckan.model.meta import
from .base import Base


Expand All @@ -22,14 +22,15 @@ class MolecularRelationData(Base):
molecules_id from molecules data table are stored here.
Which internally, relates to the packages and their ids.
These two are combined in this table, for simplier access.
These two are combined in this table, for simpler access.
"""

id = Column(u'id', _types.Integer, primary_key=True, autoincrement=True, nullable=False)
molecules_id = Column(u'molecules_id', _types.UnicodeText, ForeignKey('molecules.id'), nullable=False)
package_id = Column(u'package_id', _types.UnicodeText, ForeignKey('package.id'), nullable=False)

#package = relationship(_package.Package, backref="molecular_relation_data")

@classmethod
def create(cls, molecules_id, package_id):
"""
Expand Down Expand Up @@ -129,3 +130,6 @@ def get_molecule_data_by_package_id(cls, package_id):
molecule_data = Session.query(Molecules.inchi).filter(Molecules.id.in_(molecules_sub_query)).all()

return molecule_data


#meta.registry.map_imperatively(MolecularRelationData, MolecularRelationData.__table__)
18 changes: 13 additions & 5 deletions ckanext/rdkit_visuals/models/molecule_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from .base import Base



class Molecules(Base):
__tablename__ = 'molecules'

Expand All @@ -22,20 +21,20 @@ class Molecules(Base):
"""

id = Column(_types.Integer, primary_key=True, autoincrement=True)
package_id = Column(_types.Integer, ForeignKey('package.id'))
inchi = Column(_types.String)
smiles = Column(_types.String)
inchi_key = Column(_types.String)

exact_mass = Column(Float)
mol_formula = Column(_types.String)

# Relationship with the Package model
#package = relationship('Package')
# package = relationship('Package')

# Additional methods can be added here as needed

@classmethod
def create(cls, package_id, inchi, smiles, inchi_key, exact_mass, mol_formula):
def create(cls, inchi, smiles, inchi_key, exact_mass, mol_formula):
"""
Create a new Molecule entry and store it in the database.
Expand All @@ -49,7 +48,6 @@ def create(cls, package_id, inchi, smiles, inchi_key, exact_mass, mol_formula):
:return: The created Molecule instance
"""
new_molecule = cls(
package_id=package_id,
inchi=inchi,
smiles=smiles,
inchi_key=inchi_key,
Expand All @@ -60,4 +58,14 @@ def create(cls, package_id, inchi, smiles, inchi_key, exact_mass, mol_formula):
Session.commit()
return new_molecule

@classmethod
def _get_inchi_from_db(cls, inchi_key):
"""
:param inchi_key:
:return: the id of the molecule
"""

molecule_id_result = Session.query(Molecules.id).filter(Molecules.inchi_key == inchi_key).all()

return molecule_id_result

0 comments on commit 4dac2a1

Please sign in to comment.