Skip to content

Commit

Permalink
Merge pull request #33 from xchem/xtalforms
Browse files Browse the repository at this point in the history
Xtalforms
  • Loading branch information
ConorFWild authored Feb 21, 2024
2 parents d1617ab + 9f3757a commit f862d4c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 20 deletions.
12 changes: 11 additions & 1 deletion src/ligand_neighbourhood_alignment/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,16 @@ def _generate_assembly(
# op = gemmi.Op(generator.triplet)
op = gemmi.Op(_transform)
# chain_clone = structure[0][generator.chain].clone()
chain_clone = structure[0][_chain].clone()
try:
chain_clone = structure[0][_chain].clone()
except Exception as e:
raise Exception(
'An Exception occurred in generating the biological assemblies\n'
f'Based on the assembly, the expected chains were: {xtalform_assembly.chains}\n'
f'However the chains in the structure were: {[_x.name for _x in structure[0]]}\n'
'XCA does not currently handle datasets with a mis-match between the xtalform chains.\n'
'You should ensure that the chain names are consistent with the reference dataset for the xtalforms.'
)

for residue in chain_clone:
for atom in residue:
Expand Down Expand Up @@ -1283,6 +1292,7 @@ def _update(
_structure,
moving_ligand_id,
reference_ligand_id,
ligand_neighbourhoods[moving_ligand_id],
alignability_graph,
ligand_neighbourhood_transforms,
conformer_site_transforms,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ def _align_structure(
_structure,
moving_ligand_id: tuple[str, str, str],
reference_ligand_id: tuple[str, str, str],
neighbourhood: dt.Neighbourhood,
g,
neighbourhood_transforms: dict[tuple[tuple[str, str, str], tuple[str, str, str]], dt.Transform],
conformer_site_transforms: dict[tuple[str, str], dt.Transform],
Expand Down Expand Up @@ -304,6 +305,13 @@ def _align_structure(

_structure = superpose_structure(running_transform, _structure)

# Drop chains without atoms in neighbourhood
neighbourhood_chains = set([_atom_id[0] for _atom_id in neighbourhood.atoms])
for _model in _structure:
for _chain in _model:
if _chain.name not in neighbourhood_chains:
_model.remove_chain(_chain.name)

# Write the fully aligned structure
_structure.write_pdb(str(out_path))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
)

# from ligand_neighbourhood_alignment.save_sites import save_sites
from ligand_neighbourhood_alignment.structures import get_structures, get_transform_from_residues, _get_transform_from_residues
from ligand_neighbourhood_alignment.structures import get_structures, get_transform_from_residues, \
_get_transform_from_residues


def get_components(g):
Expand Down Expand Up @@ -150,9 +151,9 @@ def get_sites_from_conformer_sites(conformer_sites: ConformerSites, neighbourhoo


def get_xtalform_sites_from_canonical_sites(
canonical_sites: CanonicalSites,
assigned_xtalforms: AssignedXtalForms,
xtalforms: XtalForms,
canonical_sites: CanonicalSites,
assigned_xtalforms: AssignedXtalForms,
xtalforms: XtalForms,
):
"""
Each canonical site may occur in several forms, depending on the
Expand Down Expand Up @@ -212,7 +213,6 @@ def get_xtalform_sites_from_canonical_sites(


def get_subsite_transforms(sites: CanonicalSites, structures):

transforms = {}
for site_id, site in zip(sites.site_ids, sites.sites):
rss = site.reference_ligand_id.dtag
Expand All @@ -227,21 +227,22 @@ def get_subsite_transforms(sites: CanonicalSites, structures):

return transforms


from ligand_neighbourhood_alignment import dt


def _update_conformer_site_transforms(
conformer_site_transforms,
canonical_site: dt.CanonicalSite,
conformer_sites: dict[str, dt.ConformerSite],
conformer_site_transforms,
canonical_site: dt.CanonicalSite,
conformer_sites: dict[str, dt.ConformerSite],
structures,
):

):
ref_conformer_site = conformer_sites[canonical_site.reference_conformer_site_id]
ref_conformer_site_residues = ref_conformer_site.residues

for conformer_site_id in canonical_site.conformer_site_ids:
key = (canonical_site.reference_conformer_site_id, conformer_site_id)
if key not in conformer_site_transforms:

conformer_site = conformer_sites[conformer_site_id]
# conformer_site_residues = conformer_site.residues

Expand All @@ -253,8 +254,6 @@ def _update_conformer_site_transforms(

conformer_site_transforms[key] = dt.Transform(transform.vec.tolist(), transform.mat.tolist())



# transforms = {}
# for site_id, site in zip(sites.site_ids, sites.sites):
# rss = site.reference_ligand_id.dtag
Expand Down Expand Up @@ -289,14 +288,15 @@ def get_site_transforms(sites: CanonicalSites, structures):

return transforms


def _update_canonical_site_transforms(
canonical_site_transforms: dict[str, dt.Transform],
canonical_site_transforms: dict[str, dt.Transform],
canonical_site_id,
canonical_site: dt.CanonicalSite,
# canonical_sites: dict[str, dt.CanonicalSite],
canonical_site: dt.CanonicalSite,
# canonical_sites: dict[str, dt.CanonicalSite],
conformer_sites: dict[str, dt.ConformerSite],
structures,
):
):
rss = structures[canonical_site.global_reference_dtag]
ref_site_all_ress = [
(chain.name, res.seqid.num) for model in rss for chain in model for res in chain
Expand All @@ -311,6 +311,7 @@ def _update_canonical_site_transforms(
transform.mat.tolist(),
)


def _update_reference_structure_transforms(
reference_structure_transforms,
key,
Expand All @@ -327,8 +328,8 @@ def _update_reference_structure_transforms(
transform.mat.tolist(),
)

def _generate_sites_from_components(_source_dir: Path):

def _generate_sites_from_components(_source_dir: Path):
logger.info(f"Source dir: {_source_dir}")
g = read_graph(_source_dir)
neighbourhoods: LigandNeighbourhoods = read_neighbourhoods(_source_dir)
Expand Down Expand Up @@ -395,4 +396,3 @@ def _generate_sites_from_components(_source_dir: Path):
save_site_transforms(site_transforms, _source_dir)

return canonical_sites

0 comments on commit f862d4c

Please sign in to comment.