o
    rqi	                     @   s   d dl Z d dlZd dlmZ d dlZd dlmZ d dlmZ d dl	m
Z
 d dlmZmZ ddlmZ dd	lmZ d
gZe
jejejdG dd
 d
eZdd ZdS )    N)Any)Models)
TorchModel)MODELS)	ModelFileTasks   )model_config)	AlphaFoldUnifoldForProteinStructrue)module_namec                       sL   e Zd Zedd Z fddZdd Zdd Zed	d
 Z	dd Z
  ZS )r   c                 C   s   | j ddd dS )z+Add model-specific arguments to the parser.z--model-namezchoose the model config)helpN)add_argument)parser r   n/home/app/PaddleOCR-VL/.venv_paddleocr/lib/python3.10/site-packages/modelscope/models/science/unifold/model.pyadd_args   s   
z#UnifoldForProteinStructrue.add_argsc           	         s   t    t }g }|D ]}|d|  |d|  |||  q||}t| || _t	| jj
dd}t|| _|| _tj|d tj}t|d d }dd | D }| j| d S )	Nz--T)trainZ	model_dirZemaparamsc                 S   s*   i | ]\}}d  |d dd |qS ).r   N)joinsplit).0kvr   r   r   
<dictcomp>5   s    z7UnifoldForProteinStructrue.__init__.<locals>.<dictcomp>)super__init__argparseArgumentParserr   append
parse_argsbase_architectureargsr	   
model_namer
   modelconfigospathr   r   ZTORCH_MODEL_BIN_FILEtorchloaditemsZload_state_dict)	selfkwargsr   Z
parse_commkeyr#   r&   Z
param_pathZ
state_dict	__class__r   r   r      s0   


z#UnifoldForProteinStructrue.__init__c                 C      | j  | _ | S N)r%   halfr,   r   r   r   r3   ;      zUnifoldForProteinStructrue.halfc                 C   r1   r2   )r%   bfloat16r4   r   r   r   r6   ?   r5   z#UnifoldForProteinStructrue.bfloat16c                 C   s   | |S )zBuild a new model instance.r   )clsr#   taskr   r   r   build_modelC   s   z&UnifoldForProteinStructrue.build_modelc                 K   s   | j |}|| jjfS r2   )r%   forwardr&   Zloss)r,   batchr-   Zoutputsr   r   r   r:   H   s   z"UnifoldForProteinStructrue.forward)__name__
__module____qualname__staticmethodr   r   r3   r6   classmethodr9   r:   __classcell__r   r   r/   r   r      s    

c                 C   s   t | dd| _d S )Nr$   Zmodel_2)getattrr$   )r#   r   r   r   r"   M   s   r"   )r   r'   typingr   r)   Zmodelscope.metainfor   Zmodelscope.modelsr   Zmodelscope.models.builderr   Zmodelscope.utils.constantr   r   r&   r	   Zmodules.alphafoldr
   __all__Zregister_moduleZprotein_structureZunifoldr   r"   r   r   r   r   <module>   s   8